58 lines
1.3 KiB
C++
Raw Permalink Normal View History

2017-08-09 09:29:32 +08:00
#include <common.h>
#include <log.h>
2023-02-07 05:34:06 -05:00
int log_level = log_info;
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
int enable_log_position = 0;
int enable_log_color = 1;
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
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;
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
time_t timer;
char buffer[100];
struct tm* tm_info;
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
time(&timer);
tm_info = localtime(&timer);
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
if (enable_log_color)
printf("%s", log_color[level]);
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
strftime(buffer, 100, "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s][%s]", buffer, log_text[level]);
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
if (enable_log_position) printf("[%s,func:%s,line:%d]", file, function, line);
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if (enable_log_color)
printf("%s", RESET);
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
// printf("\n");
// if(enable_log_color)
// printf(log_color[level]);
fflush(stdout);
2017-08-09 09:29:32 +08:00
2023-02-07 05:34:06 -05:00
if (log_level == log_fatal) {
about_to_exit = 1;
}
2017-08-09 09:29:32 +08:00
}
2023-02-07 05:34:06 -05:00
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);
2017-08-09 09:29:32 +08:00
}