diff --git a/code/DefaultLogger.cpp b/code/DefaultLogger.cpp index 7f468874b..85e2b6702 100644 --- a/code/DefaultLogger.cpp +++ b/code/DefaultLogger.cpp @@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FileLogStream.h" #include +#include namespace Assimp { @@ -68,17 +69,24 @@ struct LogStreamInfo { // empty } + + // Destructor + ~LogStreamInfo() + { + // empty + } }; // --------------------------------------------------------------------------- // Creates the only singleton instance Logger *DefaultLogger::create(const std::string &name, LogSeverity severity) { - m_pLogger = new DefaultLogger( name, severity ); + if ( NULL == m_pLogger ) + m_pLogger = new DefaultLogger( name, severity ); return m_pLogger; } // --------------------------------------------------------------------------- -void DefaultLogger::set (Logger *logger) +void DefaultLogger::set( Logger *logger ) { if (!logger) { @@ -110,20 +118,20 @@ void DefaultLogger::kill() // --------------------------------------------------------------------------- // Debug message -void DefaultLogger::debug(const std::string &message) +void DefaultLogger::debug( const std::string &message ) { if ( m_Severity == Logger::NORMAL ) return; - const std::string msg( "Debug: " + message ); + const std::string msg( "Debug, thread " + getThreadID() + " :" + message ); writeToStreams( msg, Logger::DEBUGGING ); } // --------------------------------------------------------------------------- // Logs an info -void DefaultLogger::info(const std::string &message) +void DefaultLogger::info( const std::string &message ) { - const std::string msg( "Info: " + message ); + const std::string msg( "Info: " + getThreadID() + " :" + message ); writeToStreams( msg , Logger::INFO ); } @@ -131,7 +139,7 @@ void DefaultLogger::info(const std::string &message) // Logs a warning void DefaultLogger::warn( const std::string &message ) { - const std::string msg( "Warn: " + message ); + const std::string msg( "Warn: " + getThreadID() + " :"+ message ); writeToStreams( msg, Logger::WARN ); } @@ -139,7 +147,7 @@ void DefaultLogger::warn( const std::string &message ) // Logs an error void DefaultLogger::error( const std::string &message ) { - const std::string msg( "Error: " + message ); + const std::string msg( "Error: "+ getThreadID() + " :" + message ); writeToStreams( msg, Logger::ERR ); } @@ -258,8 +266,7 @@ void DefaultLogger::writeToStreams(const std::string &message, { if ( message.empty() ) return; - - for ( ConstStreamIt it = this->m_StreamArray.begin(); + for ( ConstStreamIt it = m_StreamArray.begin(); it != m_StreamArray.end(); ++it) { @@ -276,6 +283,26 @@ void DefaultLogger::writeToStreams(const std::string &message, } } +// --------------------------------------------------------------------------- +// Returns thread id, if not supported only a zero will be returned. +std::string DefaultLogger::getThreadID() +{ + std::string thread_id( "0" ); +#ifdef WIN32 + HANDLE hThread = GetCurrentThread(); + if ( hThread ) + { + std::stringstream thread_msg; + thread_msg << ::GetCurrentThreadId() << " "; + return thread_msg.str(); + } + else + return thread_id; +#else + return thread_id; +#endif +} + // --------------------------------------------------------------------------- } // Namespace Assimp diff --git a/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj b/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj index ecc96759c..6e99c51ac 100644 --- a/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj +++ b/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj @@ -653,11 +653,11 @@ @@ -2694,11 +2694,11 @@ > diff --git a/include/DefaultLogger.h b/include/DefaultLogger.h index dd756d0f2..66773b364 100644 --- a/include/DefaultLogger.h +++ b/include/DefaultLogger.h @@ -131,6 +131,11 @@ private: /** @brief Writes message into a file */ void writeToStreams(const std::string &message, ErrorSeverity ErrorSev ); + /** @brief Returns the thread id. + * @remark This is an OS specific feature, if not supported, a zero will be returned. + */ + std::string getThreadID(); + private: // Aliases for stream container typedef std::vector StreamArray; diff --git a/include/LogStream.h b/include/LogStream.h index 5d72a99cb..22c2ccae0 100644 --- a/include/LogStream.h +++ b/include/LogStream.h @@ -7,7 +7,7 @@ namespace Assimp { // --------------------------------------------------------------------------- /** @class LogStream - * @brief Abstract interface for log stream implementations. + * @brief Abstract interface for log stream implementations. */ class ASSIMP_API LogStream { diff --git a/workspaces/vc8/assimp_view.vcproj b/workspaces/vc8/assimp_view.vcproj index 9d24c8955..4d858155a 100644 --- a/workspaces/vc8/assimp_view.vcproj +++ b/workspaces/vc8/assimp_view.vcproj @@ -99,6 +99,87 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - -