1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| #include "LocalPrintf.h"
NotifyLevel NS_Default = NL_ALL;
void local_set_notify_severity(const NotifyLevel& ns)
{
NS_Default = ns;
}
void local_printf(const char* format, ...)
{
char fm_buffer[512];
int fm_len = 0;
va_list ap;
va_start(ap, format);
fm_len = vsnprintf(fm_buffer, 512, format, ap);
va_end(ap);
printf("%s", fm_buffer);
}
bool level_check(const NotifyLevel& ns, const NotifyLevel& dns, char* pre)
{
if (ns & dns)
{
printf(pre);
return true;
}
return false;
}
void local_printf_ex(const NotifyLevel& ns, const char* format, ...)
{
int iHit = 0;
if ((iHit <= 1) && level_check(ns, NL_ALWAYS, "[ALWAYS]")) iHit++;
if ((iHit <= 1) && level_check(ns, NL_FATAL, "[FATAL]")) iHit++;
if ((iHit <= 1) && level_check(ns, NL_WARN, "[WARN]")) iHit++;
if ((iHit <= 1) && level_check(ns, NL_NOTICE, "[NOTICE]")) iHit++;
if ((iHit <= 1) && level_check(ns, NL_INFO, "[INFO]")) iHit++;
if ((iHit <= 1) && level_check(ns, NL_DEBUG_INFO, "[DEBUG_INFO]")) iHit++;
if ((iHit <= 1) && level_check(ns, NL_DEBUG_FP, "[DEBUG_FP]")) iHit++;
if (iHit < 1) return;
char fm_buffer[512];
int fm_len = 0;
va_list ap;
va_start(ap, format);
fm_len = vsnprintf(fm_buffer, 512, format, ap);
va_end(ap);
printf("%s", fm_buffer);
}
|