wangyu-udp2raw/log.cpp

63 lines
1.2 KiB
C++
Raw Permalink Normal View History

#include "log.h"
2017-07-24 21:18:58 +08:00
int log_level=log_info;
2017-07-25 01:54:09 +08:00
2017-07-26 17:53:15 +08:00
int enable_log_position=0;
int enable_log_color=1;
2017-07-26 08:51:05 +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);
if(enable_log_color)
2017-08-04 18:35:51 +08:00
printf("%s",log_color[level]);
2017-07-24 21:18:58 +08:00
strftime(buffer, 100, "%Y-%m-%d %H:%M:%S", tm_info);
2017-07-29 20:32:26 +08:00
printf("[%s][%s]",buffer,log_text[level]);
2017-07-24 21:18:58 +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);
if(enable_log_color)
2017-08-04 18:35:51 +08:00
printf("%s",RESET);
2017-07-24 21:18:58 +08:00
//printf("\n");
2017-07-30 13:39:18 +08:00
//if(enable_log_color)
//printf(log_color[level]);
fflush(stdout);
2017-08-04 18:35:51 +08:00
if(log_level==log_fatal)
2017-08-04 23:08:45 +08:00
{
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)
2017-08-04 18:35:51 +08:00
printf("%s",log_color[level]);
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if(enable_log_color)
2017-08-04 18:35:51 +08:00
printf("%s",RESET);
2017-07-24 21:18:58 +08:00
fflush(stdout);
2017-07-24 21:18:58 +08:00
}