summaryrefslogtreecommitdiffstats
path: root/libnetdata/log
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libnetdata/log/log.c101
-rw-r--r--libnetdata/log/log.h24
2 files changed, 102 insertions, 23 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
diff --git a/libnetdata/log/log.h b/libnetdata/log/log.h
index 4cb62e955..ae86720cb 100644
--- a/libnetdata/log/log.h
+++ b/libnetdata/log/log.h
@@ -47,10 +47,6 @@ extern "C" {
#define D_ACLK_SYNC 0x0000000800000000
#define D_SYSTEM 0x8000000000000000
-//#define DEBUG (D_WEB_CLIENT_ACCESS|D_LISTENER|D_RRD_STATS)
-//#define DEBUG 0xffffffff
-#define DEBUG (0)
-
extern int web_server_is_multithreaded;
extern uint64_t debug_flags;
@@ -65,6 +61,13 @@ extern const char *stderr_filename;
extern const char *stdout_filename;
extern const char *facility_log;
+#ifdef ENABLE_ACLK
+extern const char *aclklog_filename;
+extern int aclklog_fd;
+extern FILE *aclklog;
+extern int aclklog_enabled;
+#endif
+
extern int access_log_syslog;
extern int error_log_syslog;
extern int output_log_syslog;
@@ -78,16 +81,15 @@ extern void reopen_all_log_files();
static inline void debug_dummy(void) {}
-#define error_log_limit_reset() do { error_log_errors_per_period = error_log_errors_per_period_backup; error_log_limit(1); } while(0)
-#define error_log_limit_unlimited() do { \
- error_log_limit_reset(); \
- error_log_errors_per_period = ((error_log_errors_per_period_backup * 10) < 10000) ? 10000 : (error_log_errors_per_period_backup * 10); \
- } while(0)
+void error_log_limit_reset(void);
+void error_log_limit_unlimited(void);
#ifdef NETDATA_INTERNAL_CHECKS
#define debug(type, args...) do { if(unlikely(debug_flags & type)) debug_int(__FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
+#define internal_error(condition, args...) do { if(unlikely(condition)) error_int("IERR", __FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
#else
#define debug(type, args...) debug_dummy()
+#define internal_error(args...) debug_dummy()
#endif
#define info(args...) info_int(__FILE__, __FUNCTION__, __LINE__, ##args)
@@ -103,6 +105,10 @@ extern void error_int( const char *prefix, const char *file, const char *functio
extern void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) NORETURN PRINTFLIKE(4, 5);
extern void log_access( const char *fmt, ... ) PRINTFLIKE(1, 2);
+#ifdef ENABLE_ACLK
+extern void log_aclk_message_bin( const char *data, const size_t data_len, int tx, const char *mqtt_topic, const char *message_name);
+#endif
+
# ifdef __cplusplus
}
# endif