forked from viknet365/pmaxd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.h
124 lines (96 loc) · 2.43 KB
/
debug.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#define DEBUG(x,...) log_dfl(x,__FUNCTION__,__LINE__,__VA_ARGS__);
void (*LOG)(int, const char *, va_list arg);
int (*LOG_setmask)(int);
/* In a header somewhere */
void log_console(int priority, const char *format, va_list arg);
int log_console_setlogmask(int mask);
/* Private storage for the current mask */
static int log_consolemask;
log_dfl(int priority,const char *function, int line,const char *format, ...)
{
va_list arglist;
va_start(arglist,format);
char expanded_log[1024]="[";
char expanded_line[6];
time_t rawtime;
struct tm * timeinfo;
char buffertime [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffertime,80,"%c",timeinfo);
strcat(expanded_log,buffertime);
strcat(expanded_log," ");
// strcat(expanded_log,function);
// strcat(expanded_log,":");
// sprintf(expanded_line,"%04d]",line);
// strcat(expanded_log,expanded_line);
strcat(expanded_log,format);
LOG(priority,expanded_log,arglist);
va_end(arglist);
}
log_fl(int priority,const char *function, int line,const char *format, ...)
{
va_list arglist;
char expanded_log[1024]="[";
char expanded_line[6];
// strcat(expanded_log,function);
// strcat(expanded_log,":");
// sprintf(expanded_line,"%04d]",line);
// strcat(expanded_log,expanded_line);
strcat(expanded_log,format);
va_start(arglist, format);
LOG(priority,expanded_log,arglist);
va_end(arglist);
}
int log_console_setlogmask(int mask)
{
int oldmask = log_consolemask;
if(mask == 0)
return oldmask; /* POSIX definition for 0 mask */
log_consolemask = mask;
return oldmask;
}
void log_console(int priority, const char *format, va_list arg)
{
// va_list arglist;
const char *loglevel;
// va_start(arglist, format);
/* Return on MASKed log priorities */
if (!(LOG_MASK(priority) & log_consolemask))
return;
switch(priority)
{
case LOG_EMERG:
loglevel = "EMERG: ";
break;
case LOG_ALERT:
loglevel = "ALERT: ";
break;
case LOG_CRIT:
loglevel = "CRIT: ";
break;
case LOG_ERR:
loglevel = "ERR: ";
break;
case LOG_WARNING:
loglevel = "WARNING: ";
break;
case LOG_NOTICE:
loglevel = "NOTICE: ";
break;
case LOG_INFO:
loglevel = "INFO: ";
break;
case LOG_DEBUG:
loglevel = "DEBUG: ";
break;
default:
loglevel = "UNKNOWN: ";
break;
}
printf(" %s", loglevel);
vprintf(format, arg);
printf("\n");
fflush(stdout);
//va_end(arglist);
}