-
Notifications
You must be signed in to change notification settings - Fork 187
/
log.cpp
executable file
·63 lines (47 loc) · 1.18 KB
/
log.cpp
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
#include <common.h>
#include <log.h>
int log_level=log_info;
int enable_log_position=0;
int enable_log_color=1;
void log0(const char * file,const char * function,int line,int level,const char* str, ...) {
if(level>log_level) return ;
if(level>log_trace||level<0) return ;
time_t timer;
char buffer[100];
struct tm* tm_info;
time(&timer);
tm_info = localtime(&timer);
if(enable_log_color)
printf("%s",log_color[level]);
strftime(buffer, 100, "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s][%s]",buffer,log_text[level]);
if(enable_log_position)printf("[%s,func:%s,line:%d]",file,function,line);
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if(enable_log_color)
printf("%s",RESET);
//printf("\n");
//if(enable_log_color)
//printf(log_color[level]);
fflush(stdout);
if(log_level==log_fatal)
{
about_to_exit=1;
}
}
void log_bare(int level,const char* str, ...)
{
if(level>log_level) return ;
if(level>log_trace||level<0) return ;
if(enable_log_color)
printf("%s",log_color[level]);
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if(enable_log_color)
printf("%s",RESET);
fflush(stdout);
}