@cryptotaxi247 / netdata-1 / commits / 203f98208

do not even write access.log if it set to none or /dev/null; when set to system it goes to stderr

Costa Tsaousis (ktsaou) committed Jan 9, 2018 at 01:12 UTC 203f98208e05ec204b4d59bea915606cf8af94f7
1 file changed +18 -6
src/log.c
+18 -6
@@ -55,13 +55,16 @@ static inline void log_unlock() {
55 }
56
57 int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) {
58 - int f;
58 + int f, devnull = 0;
59
60 - if(!filename || !*filename || !strcmp(filename, "none"))
60 + if(!filename || !*filename || !strcmp(filename, "none") || !strcmp(filename, "/dev/null")) {
61 filename = "/dev/null";
62 + devnull =1;
63 + }
64
65 if(!strcmp(filename, "syslog")) {
66 filename = "/dev/null";
67 + devnull = 1;
68 syslog_init();
69 if(enabled_syslog) *enabled_syslog = 1;
70 }
@@ -70,8 +73,10 @@ int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog)
73 // don't do anything if the user is willing
74 // to have the standard one
75 if(!strcmp(filename, "system")) {
73 - if(fd != -1) return fd;
74 - filename = "stdout";
76 + if(fd != -1 && fp != &stdaccess)
77 + return fd;
78 +
79 + filename = "stderr";
80 }
81
82 if(!strcmp(filename, "stdout"))
@@ -88,6 +93,11 @@ int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog)
93 }
94 }
95
96 + if(devnull && fp == &stdaccess) {
97 + fd = -1;
98 + *fp = NULL;
99 + }
100 +
101 // if there is a level-2 file pointer
102 // flush it before switching the level-1 fds
103 if(fp && *fp)
@@ -397,7 +407,8 @@ void log_access( const char *fmt, ... ) {
407 if(stdaccess) {
408 static netdata_mutex_t access_mutex = NETDATA_MUTEX_INITIALIZER;
409
400 - netdata_mutex_lock(&access_mutex);
410 + if(web_server_is_multithreaded)
411 + netdata_mutex_lock(&access_mutex);
412
413 char date[LOG_DATE_LENGTH];
414 log_date(date, LOG_DATE_LENGTH);
@@ -408,6 +419,7 @@ void log_access( const char *fmt, ... ) {
419 va_end( args );
420 fputc('\n', stdaccess);
421
411 - netdata_mutex_unlock(&access_mutex);
422 + if(web_server_is_multithreaded)
423 + netdata_mutex_unlock(&access_mutex);
424 }
425 }