From c9f0b694de97913867c4e9d61a47aa5883fe913d Mon Sep 17 00:00:00 2001 From: crs Date: Tue, 23 Oct 2001 21:23:29 +0000 Subject: [PATCH] can now filter logging by level. --- base/CLog.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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,