From 10f4e9455763973a37acedc2cccae144e5874a48 Mon Sep 17 00:00:00 2001 From: crs Date: Mon, 3 Jun 2002 16:36:45 +0000 Subject: [PATCH] added a method to set the filter given a priority string (instead of a number). fixed a comment related to what those priority strings are. added a CLOG_PRINT priority which is never filtered and suppresses the trace info and the priority level message. it's intended as a way to output a message through the logger without getting extra output. --- base/CLog.cpp | 41 ++++++++++++++++++++++++++++------------- base/CLog.h | 6 +++++- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/base/CLog.cpp b/base/CLog.cpp index 145a2a2c..a9098c8e 100644 --- a/base/CLog.cpp +++ b/base/CLog.cpp @@ -96,6 +96,11 @@ void CLog::printt(const char* file, int line, sprintf(buffer + g_priorityPad, "%s,%d:", file, line); buffer[pad - 1] = ' '; + // discard file and line if priority < 0 + if (priority < 0) { + buffer += pad - g_priorityPad; + } + // output buffer output(priority, buffer); @@ -128,6 +133,20 @@ CLog::Lock CLog::getLock() return (s_lock == dummyLock) ? NULL : s_lock; } +bool CLog::setFilter(const char* maxPriority) +{ + if (maxPriority != NULL) { + for (int i = 0; i < g_numPriority; ++i) { + if (strcmp(maxPriority, g_priority[i]) == 0) { + setFilter(i); + return true; + } + } + return false; + } + return true; +} + void CLog::setFilter(int maxPriority) { CHoldLock lock(s_lock); @@ -151,15 +170,7 @@ int CLog::getMaxPriority() if (s_maxPriority == -1) { s_maxPriority = g_defaultMaxPriority; - const char* priEnv = getenv("SYN_LOG_PRI"); - if (priEnv != NULL) { - for (int i = 0; i < g_numPriority; ++i) { - if (strcmp(priEnv, g_priority[i]) == 0) { - s_maxPriority = i; - break; - } - } - } + setFilter(getenv("SYN_LOG_PRI")); } return s_maxPriority; @@ -167,14 +178,18 @@ int CLog::getMaxPriority() void CLog::output(int priority, char* msg) { - assert(priority >= 0 && priority < g_numPriority); + assert(priority >= -1 && priority < g_numPriority); assert(msg != 0); if (priority <= getMaxPriority()) { // insert priority label - int n = strlen(g_priority[priority]); - sprintf(msg + g_maxPriorityLength - n, "%s:", g_priority[priority]); - msg[g_maxPriorityLength + 1] = ' '; + int n = -g_prioritySuffixLength; + if (priority >= 0) { + n = strlen(g_priority[priority]); + sprintf(msg + g_maxPriorityLength - n, + "%s:", g_priority[priority]); + msg[g_maxPriorityLength + 1] = ' '; + } // put a newline at the end #if defined(CONFIG_PLATFORM_WIN32) diff --git a/base/CLog.h b/base/CLog.h index 63d97174..6a1189bd 100644 --- a/base/CLog.h +++ b/base/CLog.h @@ -30,7 +30,10 @@ public: // priority is discarded. the default priority is 4 (INFO) // (unless built without NDEBUG in which case it's 5 (DEBUG)). // the default can be overridden by setting the SYN_LOG_PRI env - // var to "CRIT", "ERR", etc. + // var to "FATAL", "ERROR", etc. setFilter(const char*) returns + // true if the priority name was recognized; if name == NULL + // then it simply returns true. + static bool setFilter(const char* name); static void setFilter(int); static int getFilter(); @@ -73,6 +76,7 @@ private: #define CLOG_TRACE __FILE__, __LINE__, #endif +#define CLOG_PRINT CLOG_TRACE "%z\057" #define CLOG_CRIT CLOG_TRACE "%z\060" #define CLOG_ERR CLOG_TRACE "%z\061" #define CLOG_WARN CLOG_TRACE "%z\062"