diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2023-05-02 21:41:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-02 21:41:38 +0000 |
commit | ab41c4b5bbd17132fb83e3fbeda4683e037c956e (patch) | |
tree | fa06096cae2d5ca5d0cce7e50a32a344b5d890c0 /libnetdata | |
parent | 2241df1913806f8cdd047f6abcc05c14d582ce49 (diff) |
Address log issue (#14958)
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/log/log.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/libnetdata/log/log.c b/libnetdata/log/log.c index 1dcdba9c21..6832d628d4 100644 --- a/libnetdata/log/log.c +++ b/libnetdata/log/log.c @@ -582,9 +582,11 @@ void reopen_all_log_files() { open_log_file(STDERR_FILENO, stderr, stdcollector_filename, &collector_log_syslog, 0, NULL); if(stderr_filename) { - log_lock(); - stderror = open_log_file(stdcollector_fd, stderror, stderr_filename, &error_log_syslog, 1, &stdcollector_fd); - log_unlock(); + // Netdata starts using stderr and if it has success to open file it redirects + FILE *fp = open_log_file(stdcollector_fd, stderror, stderr_filename, + &error_log_syslog, 1, &stdcollector_fd); + if (fp) + stderror = fp; } #ifdef ENABLE_ACLK @@ -606,9 +608,10 @@ void open_all_log_files() { open_log_file(STDOUT_FILENO, stdout, stdout_filename, &output_log_syslog, 0, NULL); open_log_file(STDERR_FILENO, stderr, stdcollector_filename, &collector_log_syslog, 0, NULL); - log_lock(); - stderror = open_log_file(stdcollector_fd, NULL, stderr_filename, &error_log_syslog, 1, &stdcollector_fd); - log_unlock(); + // Netdata starts using stderr and if it has success to open file it redirects + FILE *fp = open_log_file(stdcollector_fd, NULL, stderr_filename, &error_log_syslog, 1, &stdcollector_fd); + if (fp) + stderror = fp; #ifdef ENABLE_ACLK if(aclklog_enabled) @@ -631,7 +634,7 @@ int error_log_limit(int reset) { static time_t start = 0; static unsigned long counter = 0, prevented = 0; - FILE *fp = (!stderror) ? stderr : stderror; + FILE *fp = stderror; // fprintf(fp, "FLOOD: counter=%lu, allowed=%lu, backup=%lu, period=%llu\n", counter, error_log_errors_per_period, error_log_errors_per_period_backup, (unsigned long long)error_log_throttle_period); @@ -778,7 +781,7 @@ void debug_int( const char *file, const char *function, const unsigned long line void info_int( int is_collector, const char *file __maybe_unused, const char *function __maybe_unused, const unsigned long line __maybe_unused, const char *fmt, ... ) { va_list args; - FILE *fp = (is_collector || !stderror) ? stderr : stderror; + FILE *fp = (is_collector) ? stderr : stderror; log_lock(); @@ -838,7 +841,7 @@ static const char *strerror_result_string(const char *a, const char *b) { (void) #endif void error_limit_int(ERROR_LIMIT *erl, const char *prefix, const char *file __maybe_unused, const char *function __maybe_unused, const unsigned long line __maybe_unused, const char *fmt, ... ) { - FILE *fp = (!stderror) ? stderr : stderror; + FILE *fp = stderror; if(erl->sleep_ut) sleep_usec(erl->sleep_ut); @@ -907,7 +910,7 @@ void error_limit_int(ERROR_LIMIT *erl, const char *prefix, const char *file __ma void error_int(int is_collector, const char *prefix, const char *file __maybe_unused, const char *function __maybe_unused, const unsigned long line __maybe_unused, const char *fmt, ... ) { // save a copy of errno - just in case this function generates a new error int __errno = errno; - FILE *fp = (is_collector || !stderror) ? stderr : stderror; + FILE *fp = (is_collector) ? stderr : stderror; va_list args; @@ -972,7 +975,7 @@ static void print_call_stack(void) { #endif void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) { - FILE *fp = (!stderror) ? stderr : stderror; + FILE *fp = stderror; // save a copy of errno - just in case this function generates a new error int __errno = errno; |