diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-08 16:27:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-08 16:27:08 +0000 |
commit | 81581f9719bc56f01d5aa08952671d65fda9867a (patch) | |
tree | 0f5c6b6138bf169c23c9d24b1fc0a3521385cb18 /libnetdata/log | |
parent | Releasing debian version 1.38.1-1. (diff) | |
download | netdata-81581f9719bc56f01d5aa08952671d65fda9867a.tar.xz netdata-81581f9719bc56f01d5aa08952671d65fda9867a.zip |
Merging upstream version 1.39.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/log')
-rw-r--r-- | libnetdata/log/README.md | 4 | ||||
-rw-r--r-- | libnetdata/log/log.c | 25 |
2 files changed, 16 insertions, 13 deletions
diff --git a/libnetdata/log/README.md b/libnetdata/log/README.md index 5f9e5bc7b..3684abd68 100644 --- a/libnetdata/log/README.md +++ b/libnetdata/log/README.md @@ -1,10 +1,10 @@ <!-- -title "Log" +title: "Log" custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/log/README.md sidebar_label: "Log" learn_status: "Published" learn_topic_type: "Tasks" -learn_rel_path: "Developers/libnetdata libraries" +learn_rel_path: "Developers/libnetdata" --> # Log diff --git a/libnetdata/log/log.c b/libnetdata/log/log.c index 1dcdba9c2..6832d628d 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; |