can now filter logging by level.

This commit is contained in:
crs 2001-10-23 21:23:29 +00:00
parent b7533aea2a
commit c9f0b694de
1 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#include "CLog.h" #include "CLog.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
@ -7,6 +8,8 @@
// CLog // CLog
// //
static int g_maxPriority = -1;
void CLog::print(const char* fmt, ...) void CLog::print(const char* fmt, ...)
{ {
// check if fmt begins with a priority argument // check if fmt begins with a priority argument
@ -76,11 +79,24 @@ void CLog::output(int priority, const char* msg)
"INFO", "INFO",
"DEBUG", "DEBUG",
}; };
static const int s_numPriority = (int)(sizeof(s_priority) /
assert(priority >= 0 && priority < (int)(sizeof(s_priority) / sizeof(s_priority[0]));
sizeof(s_priority[0]))); assert(priority >= 0 && priority < s_numPriority);
assert(msg != 0); assert(msg != 0);
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); fprintf(stderr, "%s: %s\n", s_priority[priority], msg);
} }