Add concept of verboseDebug
parent
2ffd1cb8db
commit
5e0136d737
|
@ -392,7 +392,7 @@ ASSIMP_API aiReturn aiDetachLogStream(const aiLogStream *stream) {
|
||||||
if (it == gActiveLogStreams.end()) {
|
if (it == gActiveLogStreams.end()) {
|
||||||
return AI_FAILURE;
|
return AI_FAILURE;
|
||||||
}
|
}
|
||||||
DefaultLogger::get()->detatchStream(it->second);
|
DefaultLogger::get()->detachStream( it->second );
|
||||||
delete it->second;
|
delete it->second;
|
||||||
|
|
||||||
gActiveLogStreams.erase(it);
|
gActiveLogStreams.erase(it);
|
||||||
|
@ -416,7 +416,7 @@ ASSIMP_API void aiDetachAllLogStreams(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
|
for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
|
||||||
logger->detatchStream(it->second);
|
logger->detachStream( it->second );
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
gActiveLogStreams.clear();
|
gActiveLogStreams.clear();
|
||||||
|
|
|
@ -177,6 +177,18 @@ void Logger::debug(const char* message) {
|
||||||
return OnDebug(message);
|
return OnDebug(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------
|
||||||
|
void Logger::verboseDebug(const char *message) {
|
||||||
|
|
||||||
|
// SECURITY FIX: otherwise it's easy to produce overruns since
|
||||||
|
// sometimes importers will include data from the input file
|
||||||
|
// (i.e. node names) in their messages.
|
||||||
|
if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return OnVerboseDebug(message);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
void Logger::info(const char* message) {
|
void Logger::info(const char* message) {
|
||||||
|
|
||||||
|
@ -251,7 +263,7 @@ void DefaultLogger::kill() {
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
// Debug message
|
// Debug message
|
||||||
void DefaultLogger::OnDebug( const char* message ) {
|
void DefaultLogger::OnDebug( const char* message ) {
|
||||||
if ( m_Severity == Logger::NORMAL ) {
|
if ( m_Severity < Logger::DEBUG ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +274,19 @@ void DefaultLogger::OnDebug( const char* message ) {
|
||||||
WriteToStreams( msg, Logger::Debugging );
|
WriteToStreams( msg, Logger::Debugging );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verbose debug message
|
||||||
|
void DefaultLogger::OnVerboseDebug(const char *message) {
|
||||||
|
if (m_Severity < Logger::VERBOSE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const size_t Size = MAX_LOG_MESSAGE_LENGTH + 16;
|
||||||
|
char msg[Size];
|
||||||
|
ai_snprintf(msg, Size, "Debug, T%u: %s", GetThreadID(), message);
|
||||||
|
|
||||||
|
WriteToStreams(msg, Logger::Debugging);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
// Logs an info
|
// Logs an info
|
||||||
void DefaultLogger::OnInfo( const char* message ){
|
void DefaultLogger::OnInfo( const char* message ){
|
||||||
|
@ -320,7 +345,7 @@ bool DefaultLogger::attachStream( LogStream *pStream, unsigned int severity ) {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
// Detach a stream
|
// Detach a stream
|
||||||
bool DefaultLogger::detatchStream( LogStream *pStream, unsigned int severity ) {
|
bool DefaultLogger::detachStream( LogStream *pStream, unsigned int severity ) {
|
||||||
if ( nullptr == pStream ) {
|
if ( nullptr == pStream ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
/** @brief Creates a logging instance.
|
/** @brief Creates a logging instance.
|
||||||
* @param name Name for log file. Only valid in combination
|
* @param name Name for log file. Only valid in combination
|
||||||
* with the aiDefaultLogStream_FILE flag.
|
* with the aiDefaultLogStream_FILE flag.
|
||||||
* @param severity Log severity, VERBOSE turns on debug messages
|
* @param severity Log severity, DEBUG turns on debug messages and VERBOSE turns on all messages.
|
||||||
* @param defStreams Default log streams to be attached. Any bitwise
|
* @param defStreams Default log streams to be attached. Any bitwise
|
||||||
* combination of the aiDefaultLogStream enumerated values.
|
* combination of the aiDefaultLogStream enumerated values.
|
||||||
* If #aiDefaultLogStream_FILE is specified but an empty string is
|
* If #aiDefaultLogStream_FILE is specified but an empty string is
|
||||||
|
@ -127,8 +127,8 @@ public:
|
||||||
unsigned int severity);
|
unsigned int severity);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
/** @copydoc Logger::detatchStream */
|
/** @copydoc Logger::detachStream */
|
||||||
bool detatchStream(LogStream *pStream,
|
bool detachStream(LogStream *pStream,
|
||||||
unsigned int severity);
|
unsigned int severity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -141,9 +141,12 @@ private:
|
||||||
/** @briefDestructor */
|
/** @briefDestructor */
|
||||||
~DefaultLogger();
|
~DefaultLogger();
|
||||||
|
|
||||||
/** @brief Logs debug infos, only been written when severity level VERBOSE is set */
|
/** @brief Logs debug infos, only been written when severity level DEBUG is set */
|
||||||
void OnDebug(const char* message);
|
void OnDebug(const char* message);
|
||||||
|
|
||||||
|
/** @brief Logs debug infos, only been written when severity level VERBOSE is set */
|
||||||
|
void OnVerboseDebug(const char *message);
|
||||||
|
|
||||||
/** @brief Logs an info message */
|
/** @brief Logs an info message */
|
||||||
void OnInfo(const char* message);
|
void OnInfo(const char* message);
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,8 @@ public:
|
||||||
*/
|
*/
|
||||||
enum LogSeverity {
|
enum LogSeverity {
|
||||||
NORMAL, //!< Normal granularity of logging
|
NORMAL, //!< Normal granularity of logging
|
||||||
VERBOSE //!< Debug infos will be logged, too
|
DEBUG, //!< Debug messages will be logged, but not verbose debug messages.
|
||||||
|
VERBOSE //!< All messages will be logged
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -103,6 +104,12 @@ public:
|
||||||
void debug(const char* message);
|
void debug(const char* message);
|
||||||
void debug(const std::string &message);
|
void debug(const std::string &message);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
/** @brief Writes a debug message
|
||||||
|
* @param message Debug message*/
|
||||||
|
void verboseDebug(const char *message);
|
||||||
|
void verboseDebug(const std::string &message);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
/** @brief Writes a info message
|
/** @brief Writes a info message
|
||||||
* @param message Info message*/
|
* @param message Info message*/
|
||||||
|
@ -154,7 +161,7 @@ public:
|
||||||
* if the result is 0 the stream is detached from the Logger and
|
* if the result is 0 the stream is detached from the Logger and
|
||||||
* the caller retakes the possession of the stream.
|
* the caller retakes the possession of the stream.
|
||||||
* @return true if the stream has been detached, false otherwise.*/
|
* @return true if the stream has been detached, false otherwise.*/
|
||||||
virtual bool detatchStream(LogStream *pStream,
|
virtual bool detachStream(LogStream *pStream,
|
||||||
unsigned int severity = Debugging | Err | Warn | Info) = 0;
|
unsigned int severity = Debugging | Err | Warn | Info) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -178,6 +185,16 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual void OnDebug(const char* message)= 0;
|
virtual void OnDebug(const char* message)= 0;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Called as a request to write a specific verbose debug message
|
||||||
|
* @param message Debug message. Never longer than
|
||||||
|
* MAX_LOG_MESSAGE_LENGTH characters (excluding the '0').
|
||||||
|
* @note The message string is only valid until the scope of
|
||||||
|
* the function is left.
|
||||||
|
*/
|
||||||
|
virtual void OnVerboseDebug(const char *message) = 0;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief Called as a request to write a specific info message
|
* @brief Called as a request to write a specific info message
|
||||||
|
@ -255,6 +272,11 @@ void Logger::debug(const std::string &message) {
|
||||||
return debug(message.c_str());
|
return debug(message.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------
|
||||||
|
inline void Logger::verboseDebug(const std::string &message) {
|
||||||
|
return verboseDebug(message.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
inline
|
inline
|
||||||
void Logger::error(const std::string &message) {
|
void Logger::error(const std::string &message) {
|
||||||
|
@ -285,6 +307,9 @@ void Logger::info(const std::string &message) {
|
||||||
#define ASSIMP_LOG_DEBUG_F(string, ...) \
|
#define ASSIMP_LOG_DEBUG_F(string, ...) \
|
||||||
Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__))
|
Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__))
|
||||||
|
|
||||||
|
#define ASSIMP_LOG_VERBOSE_DEBUG_F(string, ...) \
|
||||||
|
Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__))
|
||||||
|
|
||||||
#define ASSIMP_LOG_INFO_F(string, ...) \
|
#define ASSIMP_LOG_INFO_F(string, ...) \
|
||||||
Assimp::DefaultLogger::get()->info((Assimp::Formatter::format(string), __VA_ARGS__))
|
Assimp::DefaultLogger::get()->info((Assimp::Formatter::format(string), __VA_ARGS__))
|
||||||
|
|
||||||
|
@ -297,6 +322,9 @@ void Logger::info(const std::string &message) {
|
||||||
#define ASSIMP_LOG_DEBUG(string) \
|
#define ASSIMP_LOG_DEBUG(string) \
|
||||||
Assimp::DefaultLogger::get()->debug(string)
|
Assimp::DefaultLogger::get()->debug(string)
|
||||||
|
|
||||||
|
#define ASSIMP_LOG_VERBOSE_DEBUG(string) \
|
||||||
|
Assimp::DefaultLogger::get()->verboseDebug(string)
|
||||||
|
|
||||||
#define ASSIMP_LOG_INFO(string) \
|
#define ASSIMP_LOG_INFO(string) \
|
||||||
Assimp::DefaultLogger::get()->info(string)
|
Assimp::DefaultLogger::get()->info(string)
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ public:
|
||||||
(void)message; //this avoids compiler warnings
|
(void)message; //this avoids compiler warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Logs a verbose debug message */
|
||||||
|
void OnVerboseDebug(const char *message) {
|
||||||
|
(void)message; //this avoids compiler warnings
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Logs an info message */
|
/** @brief Logs an info message */
|
||||||
void OnInfo(const char* message) {
|
void OnInfo(const char* message) {
|
||||||
(void)message; //this avoids compiler warnings
|
(void)message; //this avoids compiler warnings
|
||||||
|
@ -88,7 +93,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Detach a still attached stream from logger */
|
/** @brief Detach a still attached stream from logger */
|
||||||
bool detatchStream(LogStream *pStream, unsigned int severity) {
|
bool detachStream(LogStream *pStream, unsigned int severity) {
|
||||||
(void)pStream; (void)severity; //this avoids compiler warnings
|
(void)pStream; (void)severity; //this avoids compiler warnings
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue