2017-07-24 21:18:58 +08:00
|
|
|
#include <log.h>
|
|
|
|
|
|
|
|
const int log_level=log_debug;
|
2017-07-25 00:04:49 +08:00
|
|
|
int enable_log_position=1;
|
|
|
|
int enable_log_color=1;
|
2017-07-24 21:18:58 +08:00
|
|
|
char log_text[][10]={"FATAL","ERROR","WARN","INFO","DEBUG","TRACE"};
|
|
|
|
char log_color[][10]={RED,RED,YEL,GRN,BLU,""};
|
2017-07-25 00:04:49 +08:00
|
|
|
void log0(const char * file,const char * function,int line,int level,const char* str, ...) {
|
2017-07-24 21:18:58 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-07-25 00:04:49 +08:00
|
|
|
if(enable_log_color)
|
2017-07-24 21:18:58 +08:00
|
|
|
printf(log_color[level]);
|
|
|
|
|
|
|
|
strftime(buffer, 100, "%Y-%m-%d %H:%M:%S", tm_info);
|
2017-07-25 00:04:49 +08:00
|
|
|
printf("[%s][%s]",buffer,log_text[level],file,line);
|
2017-07-24 21:18:58 +08:00
|
|
|
|
2017-07-25 00:04:49 +08:00
|
|
|
if(enable_log_position)printf("[%s,func:%s,line:%d]",file,function,line);
|
2017-07-24 21:18:58 +08:00
|
|
|
|
|
|
|
va_list vlist;
|
|
|
|
va_start(vlist, str);
|
|
|
|
vfprintf(stdout, str, vlist);
|
|
|
|
va_end(vlist);
|
2017-07-25 00:04:49 +08:00
|
|
|
if(enable_log_color)
|
|
|
|
printf(RESET);
|
2017-07-24 21:18:58 +08:00
|
|
|
//printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|