diff options
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 40 |
1 files changed, 27 insertions, 13 deletions
@@ -1,5 +1,7 @@ #include "common.h" +int web_server_is_multithreaded = 1; + const char *program_name = ""; uint64_t debug_flags = DEBUG; @@ -55,13 +57,16 @@ static inline void log_unlock() { } int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) { - int f; + int f, devnull = 0; - if(!filename || !*filename || !strcmp(filename, "none")) + if(!filename || !*filename || !strcmp(filename, "none") || !strcmp(filename, "/dev/null")) { filename = "/dev/null"; + devnull = 1; + } if(!strcmp(filename, "syslog")) { filename = "/dev/null"; + devnull = 1; syslog_init(); if(enabled_syslog) *enabled_syslog = 1; } @@ -70,8 +75,10 @@ int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) // don't do anything if the user is willing // to have the standard one if(!strcmp(filename, "system")) { - if(fd != -1) return fd; - filename = "stdout"; + if(fd != -1 && fp != &stdaccess) + return fd; + + filename = "stderr"; } if(!strcmp(filename, "stdout")) @@ -88,6 +95,11 @@ int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) } } + if(devnull && fp == &stdaccess) { + fd = -1; + *fp = NULL; + } + // if there is a level-2 file pointer // flush it before switching the level-1 fds if(fp && *fp) @@ -246,7 +258,7 @@ void debug_int( const char *file, const char *function, const unsigned long line log_date(date, LOG_DATE_LENGTH); va_start( args, fmt ); - printf("%s: %s DEBUG (%04lu@%-10.10s:%-15.15s): ", date, program_name, line, file, function); + printf("%s: %s DEBUG : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function); vprintf(fmt, args); va_end( args ); putchar('\n'); @@ -282,8 +294,8 @@ void info_int( const char *file, const char *function, const unsigned long line, log_lock(); va_start( args, fmt ); - if(debug_flags) fprintf(stderr, "%s: %s INFO : (%04lu@%-10.10s:%-15.15s): ", date, program_name, line, file, function); - else fprintf(stderr, "%s: %s INFO : ", date, program_name); + if(debug_flags) fprintf(stderr, "%s: %s INFO : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function); + else fprintf(stderr, "%s: %s INFO : %s : ", date, program_name, netdata_thread_tag()); vfprintf( stderr, fmt, args ); va_end( args ); @@ -338,8 +350,8 @@ void error_int( const char *prefix, const char *file, const char *function, cons log_lock(); va_start( args, fmt ); - if(debug_flags) fprintf(stderr, "%s: %s %s: (%04lu@%-10.10s:%-15.15s): ", date, program_name, prefix, line, file, function); - else fprintf(stderr, "%s: %s %s: ", date, program_name, prefix); + if(debug_flags) fprintf(stderr, "%s: %s %-5.5s : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, prefix, netdata_thread_tag(), line, file, function); + else fprintf(stderr, "%s: %s %-5.5s : %s : ", date, program_name, prefix, netdata_thread_tag()); vfprintf( stderr, fmt, args ); va_end( args ); @@ -369,8 +381,8 @@ void fatal_int( const char *file, const char *function, const unsigned long line log_lock(); va_start( args, fmt ); - if(debug_flags) fprintf(stderr, "%s: %s FATAL: (%04lu@%-10.10s:%-15.15s): ", date, program_name, line, file, function); - else fprintf(stderr, "%s: %s FATAL: ", date, program_name); + if(debug_flags) fprintf(stderr, "%s: %s FATAL : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function); + else fprintf(stderr, "%s: %s FATAL : %s :", date, program_name, netdata_thread_tag()); vfprintf( stderr, fmt, args ); va_end( args ); @@ -397,7 +409,8 @@ void log_access( const char *fmt, ... ) { if(stdaccess) { static netdata_mutex_t access_mutex = NETDATA_MUTEX_INITIALIZER; - netdata_mutex_lock(&access_mutex); + if(web_server_is_multithreaded) + netdata_mutex_lock(&access_mutex); char date[LOG_DATE_LENGTH]; log_date(date, LOG_DATE_LENGTH); @@ -408,6 +421,7 @@ void log_access( const char *fmt, ... ) { va_end( args ); fputc('\n', stdaccess); - netdata_mutex_unlock(&access_mutex); + if(web_server_is_multithreaded) + netdata_mutex_unlock(&access_mutex); } } |