-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.c
49 lines (39 loc) · 888 Bytes
/
logging.c
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
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/time.h>
#include <time.h>
#include "logging.h"
int loglevel=LOG_DEBUG;
void logwrite_inc_level() {
loglevel++;
}
void _logwrite(const char *function, int line, int level, const char *format, ...) {
va_list pvar;
char logbuffer[MAXPATHLEN];
char timedate[64];
struct timeval tv;
struct tm *tm;
time_t *t=&tv.tv_sec;
if (level > loglevel)
return;
va_start (pvar, format);
vsnprintf(logbuffer, sizeof(logbuffer), format, pvar);
va_end (pvar);
gettimeofday(&tv, NULL);
tm=localtime(t);
strftime(timedate, sizeof(timedate), "%Y-%m-%d %H:%M:%S", tm);
if (function)
printf("%s.%03d %s/%d %s\n",
timedate,
(int) tv.tv_usec/1000,
function,
line,
logbuffer);
else
printf("%s.%03d %s\n",
timedate,
(int) tv.tv_usec/1000,
logbuffer);
}