diff --git a/base/CLog.cpp b/base/CLog.cpp index 92a32744..cb98cbbd 100644 --- a/base/CLog.cpp +++ b/base/CLog.cpp @@ -1,5 +1,6 @@ #include "CLog.h" #include +#include #include #include @@ -7,6 +8,8 @@ // CLog // +static int g_maxPriority = -1; + void CLog::print(const char* fmt, ...) { // check if fmt begins with a priority argument @@ -76,12 +79,25 @@ void CLog::output(int priority, const char* msg) "INFO", "DEBUG", }; - - assert(priority >= 0 && priority < (int)(sizeof(s_priority) / - sizeof(s_priority[0]))); + static const int s_numPriority = (int)(sizeof(s_priority) / + sizeof(s_priority[0])); + assert(priority >= 0 && priority < s_numPriority); assert(msg != 0); - fprintf(stderr, "%s: %s\n", s_priority[priority], msg); + if (g_maxPriority == -1) { + g_maxPriority = s_numPriority - 1; + const char* priEnv = getenv("SYN_LOG_PRI"); + if (priEnv != NULL) { + for (int i = 0; i < s_numPriority; ++i) + if (strcmp(priEnv, s_priority[i]) == 0) { + g_maxPriority = i; + break; + } + } + } + + if (priority <= g_maxPriority) + fprintf(stderr, "%s: %s\n", s_priority[priority], msg); } char* CLog::vsprint(int pad, char* buffer, int len,