udp2raw/log.cpp

63 lines
1.2 KiB
C++
Raw Normal View History

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