Index: ext/libicpf/src/log.cpp =================================================================== diff -u -re17c80d36eaa0430313e7d1058aa7a301d1510af -r01f412dddb725bcd82c0dce8755af7f113a101d8 --- ext/libicpf/src/log.cpp (.../log.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/log.cpp (.../log.cpp) (revision 01f412dddb725bcd82c0dce8755af7f113a101d8) @@ -42,22 +42,34 @@ const char_t* __logtype_str[] = { "debug", "info", "warning", "error" }; /// Global variable initialized when constructing log_file object -log_file* __g_log=NULL; +static log_file* __g_log=NULL; -log_file::log_file() +/** Constructs a log_file object. + * \param[in] bGlobal - states if this should be treates as a global instance of the log_file. + * Only one global log_file instance could exist in the application. + */ +log_file::log_file(bool bGlobal) : + m_bGlobal(bGlobal), + m_pszPath(NULL), + m_bLogStd(false), + m_iLogLevel(LT_DEBUG) { - __g_log=this; - m_pszPath=NULL; - m_bLogStd=false; - m_iLogLevel=LT_DEBUG; + if (m_bGlobal) + { + assert(__g_log == NULL); // there is another instance of a global log running + __g_log=this; + } #ifdef WIN32 _fmode=_O_BINARY; #endif } +/** Standard destructor + */ log_file::~log_file() { - __g_log=NULL; + if (m_bGlobal) + __g_log=NULL; delete [] m_pszPath; } @@ -71,7 +83,7 @@ */ bool create_log(const char_t* pszPath, int_t iMaxSize, int_t iLogLevel, bool bLogStd, bool bClean) { - log_file* pLog=new log_file(); + log_file* pLog=new log_file(true); if (!pLog->init(pszPath, iMaxSize, iLogLevel, bLogStd, bClean)) { delete pLog; Index: ext/libicpf/src/log.h =================================================================== diff -u -re17c80d36eaa0430313e7d1058aa7a301d1510af -r01f412dddb725bcd82c0dce8755af7f113a101d8 --- ext/libicpf/src/log.h (.../log.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/log.h (.../log.h) (revision 01f412dddb725bcd82c0dce8755af7f113a101d8) @@ -100,8 +100,8 @@ public: /** \name Construction/destruction */ /**@{*/ - log_file(); ///< Standard constructor - ~log_file(); ///< Standard destructor + log_file(bool bGlobal); ///< Standard constructor + ~log_file(); ///< Standard destructor /**@}*/ /** \name Initialization */ @@ -161,7 +161,8 @@ int_t m_iMaxSize; ///< Maximum size of the log file bool m_bLogStd; ///< Log also to stdout/stderr int_t m_iLogLevel; ///< Log level (similar to the _LOG_LEVEL, but change'able after compilation) - + bool m_bGlobal; ///< Is this the global instance of app log ? (so the LOG* macros would use it) + protected: mutex m_lock; ///< Lock for making the class thread safe };