diff options
Diffstat (limited to 'libnetdata/log/log.c')
-rw-r--r-- | libnetdata/log/log.c | 101 |
1 files changed, 87 insertions, 14 deletions
diff --git a/libnetdata/log/log.c b/libnetdata/log/log.c index 90581269d..d6793b69b 100644 --- a/libnetdata/log/log.c +++ b/libnetdata/log/log.c @@ -6,7 +6,7 @@ int web_server_is_multithreaded = 1; const char *program_name = ""; -uint64_t debug_flags = DEBUG; +uint64_t debug_flags = 0; int access_log_syslog = 1; int error_log_syslog = 1; @@ -20,6 +20,14 @@ const char *stderr_filename = NULL; const char *stdout_filename = NULL; const char *facility_log = NULL; +#ifdef ENABLE_ACLK +const char *aclklog_filename = NULL; +int aclklog_fd = -1; +FILE *aclklog = NULL; +int aclklog_syslog = 1; +int aclklog_enabled = 0; +#endif + // ---------------------------------------------------------------------------- // Log facility(https://tools.ietf.org/html/rfc5424) // @@ -562,6 +570,11 @@ void reopen_all_log_files() { if(stderr_filename) open_log_file(STDERR_FILENO, stderr, stderr_filename, &error_log_syslog, 0, NULL); +#ifdef ENABLE_ACLK + if (aclklog_enabled) + aclklog = open_log_file(aclklog_fd, aclklog, aclklog_filename, NULL, 0, &aclklog_fd); +#endif + if(stdaccess_filename) stdaccess = open_log_file(stdaccess_fd, stdaccess, stdaccess_filename, &access_log_syslog, 1, &stdaccess_fd); } @@ -572,6 +585,12 @@ void open_all_log_files() { open_log_file(STDOUT_FILENO, stdout, stdout_filename, &output_log_syslog, 0, NULL); open_log_file(STDERR_FILENO, stderr, stderr_filename, &error_log_syslog, 0, NULL); + +#ifdef ENABLE_ACLK + if(aclklog_enabled) + aclklog = open_log_file(aclklog_fd, aclklog, aclklog_filename, NULL, 0, &aclklog_fd); +#endif + stdaccess = open_log_file(stdaccess_fd, stdaccess, stdaccess_filename, &access_log_syslog, 1, &stdaccess_fd); } @@ -681,6 +700,26 @@ int error_log_limit(int reset) { return 0; } +void error_log_limit_reset(void) { + log_lock(); + + error_log_errors_per_period = error_log_errors_per_period_backup; + error_log_limit(1); + + log_unlock(); +} + +void error_log_limit_unlimited(void) { + log_lock(); + + error_log_errors_per_period = error_log_errors_per_period_backup; + error_log_limit(1); + + error_log_errors_per_period = ((error_log_errors_per_period_backup * 10) < 10000) ? 10000 : (error_log_errors_per_period_backup * 10); + + log_unlock(); +} + // ---------------------------------------------------------------------------- // debug log @@ -691,7 +730,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 : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function); + printf("%s: %s DEBUG : %s : (%04lu@%-20.20s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function); vprintf(fmt, args); va_end( args ); putchar('\n'); @@ -712,8 +751,13 @@ void info_int( const char *file, const char *function, const unsigned long line, { va_list args; + log_lock(); + // prevent logging too much - if(error_log_limit(0)) return; + if (error_log_limit(0)) { + log_unlock(); + return; + } if(error_log_syslog) { va_start( args, fmt ); @@ -724,11 +768,12 @@ void info_int( const char *file, const char *function, const unsigned long line, char date[LOG_DATE_LENGTH]; log_date(date, LOG_DATE_LENGTH); - log_lock(); - va_start( args, fmt ); - 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()); +#ifdef NETDATA_INTERNAL_CHECKS + fprintf(stderr, "%s: %s INFO : %s : (%04lu@%-20.20s:%-15.15s): ", date, program_name, netdata_thread_tag(), line, file, function); +#else + fprintf(stderr, "%s: %s INFO : %s : ", date, program_name, netdata_thread_tag()); +#endif vfprintf( stderr, fmt, args ); va_end( args ); @@ -768,8 +813,13 @@ void error_int( const char *prefix, const char *file, const char *function, cons va_list args; + log_lock(); + // prevent logging too much - if(error_log_limit(0)) return; + if (error_log_limit(0)) { + log_unlock(); + return; + } if(error_log_syslog) { va_start( args, fmt ); @@ -780,11 +830,12 @@ void error_int( const char *prefix, const char *file, const char *function, cons char date[LOG_DATE_LENGTH]; log_date(date, LOG_DATE_LENGTH); - log_lock(); - va_start( args, fmt ); - 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()); +#ifdef NETDATA_INTERNAL_CHECKS + fprintf(stderr, "%s: %s %-5.5s : %s : (%04lu@%-20.20s:%-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()); +#endif vfprintf( stderr, fmt, args ); va_end( args ); @@ -826,8 +877,11 @@ 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 : %s : (%04lu@%-10.10s:%-15.15s): ", date, program_name, thread_tag, line, file, function); - else fprintf(stderr, "%s: %s FATAL : %s : ", date, program_name, thread_tag); +#ifdef NETDATA_INTERNAL_CHECKS + fprintf(stderr, "%s: %s FATAL : %s : (%04lu@%-20.20s:%-15.15s): ", date, program_name, thread_tag, line, file, function); +#else + fprintf(stderr, "%s: %s FATAL : %s : ", date, program_name, thread_tag); +#endif vfprintf( stderr, fmt, args ); va_end( args ); @@ -877,3 +931,22 @@ void log_access( const char *fmt, ... ) { netdata_mutex_unlock(&access_mutex); } } + +#ifdef ENABLE_ACLK +void log_aclk_message_bin( const char *data, const size_t data_len, int tx, const char *mqtt_topic, const char *message_name) { + if (aclklog) { + static netdata_mutex_t aclklog_mutex = NETDATA_MUTEX_INITIALIZER; + netdata_mutex_lock(&aclklog_mutex); + + char date[LOG_DATE_LENGTH]; + log_date(date, LOG_DATE_LENGTH); + fprintf(aclklog, "%s: %s Msg:\"%s\", MQTT-topic:\"%s\": ", date, tx ? "OUTGOING" : "INCOMING", message_name, mqtt_topic); + + fwrite(data, data_len, 1, aclklog); + + fputc('\n', aclklog); + + netdata_mutex_unlock(&aclklog_mutex); + } +} +#endif |