diff options
Diffstat (limited to 'CommonLibs')
-rw-r--r-- | CommonLibs/Logger.cpp | 8 | ||||
-rw-r--r-- | CommonLibs/Logger.h | 15 |
2 files changed, 21 insertions, 2 deletions
diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp index 57d2bff..d8bfc6e 100644 --- a/CommonLibs/Logger.cpp +++ b/CommonLibs/Logger.cpp @@ -150,6 +150,7 @@ void addAlarm(const string& s) Log::~Log() { + if (mDummyInit) return; // Anything at or above LOG_CRIT is an "alarm". // Save alarms in the local list and echo them to stderr. if (mPriority <= LOG_CRIT) { @@ -162,6 +163,13 @@ Log::~Log() } +Log::Log(const char* name, const char* level, int facility) +{ + mDummyInit = true; + gLogInit(name, level, facility); +} + + ostringstream& Log::get() { assert(mPriority<numLevels); diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h index b9fd5ea..35101d8 100644 --- a/CommonLibs/Logger.h +++ b/CommonLibs/Logger.h @@ -40,10 +40,18 @@ #define _LOG(level) \ Log(LOG_##level).get() << pthread_self() \ << " " __FILE__ ":" << __LINE__ << ":" << __FUNCTION__ << ": " + +#ifdef NDEBUG +#define LOG(wLevel) \ + if (LOG_##wLevel!=LOG_DEBUG && gGetLoggingLevel(__FILE__)>=LOG_##wLevel) _LOG(wLevel) +#else #define LOG(wLevel) \ if (gGetLoggingLevel(__FILE__)>=LOG_##wLevel) _LOG(wLevel) +#endif + + #define OBJLOG(wLevel) \ - if (gGetLoggingLevel(__FILE__)>=LOG_##wLevel) _LOG(wLevel) << "obj: " << this << ' ' + LOG(wLevel) << "obj: " << this << ' ' #define LOG_ASSERT(x) { if (!(x)) LOG(EMERG) << "assertion " #x " failed"; } assert(x); @@ -66,13 +74,16 @@ class Log { std::ostringstream mStream; ///< This is where we buffer up the log entry. int mPriority; ///< Priority of current repot. + bool mDummyInit; public: Log(int wPriority) - :mPriority(wPriority) + :mPriority(wPriority), mDummyInit(false) { } + Log(const char* name, const char* level=NULL, int facility=LOG_USER); + // Most of the work is in the desctructor. /** The destructor actually generates the log entry. */ ~Log(); |