can now filter logging by level.
This commit is contained in:
parent
b7533aea2a
commit
c9f0b694de
|
@ -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,12 +79,25 @@ 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);
|
||||||
|
|
||||||
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,
|
char* CLog::vsprint(int pad, char* buffer, int len,
|
||||||
|
|
Loading…
Reference in New Issue