-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.c
43 lines (38 loc) · 905 Bytes
/
debug.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
#include<stdarg.h>
#include<stdio.h>
#include<time.h>
#include<string.h>
#include "debug.h"
extern int debugflag;
extern int printjson;
void log_format(const char* tag, const char* message, va_list args) {
time_t now;
time(&now);
char * date =ctime(&now);
date[strlen(date) - 1] = '\0';
printf("%s [%s] ", date, tag);
vprintf(message, args);
printf("\n");
}
void log_error(const char* message, ...) {
va_list args;
va_start(args, message);
log_format("error", message, args);
va_end(args);
}
void log_info(const char* message, ...) {
if (!printjson)
return;
va_list args;
va_start(args, message);
log_format("info", message, args);
va_end(args);
}
void log_debug(const char* message, ...) {
if (!debugflag)
return;
va_list args;
va_start(args, message);
log_format("debug", message, args);
va_end(args);
}