summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorTimotej S <6674623+underhood@users.noreply.github.com>2022-07-08 10:33:43 +0200
committerGitHub <noreply@github.com>2022-07-08 10:33:43 +0200
commitf8b7a9c63ba1ad01900623db563fff51dc9b5fa2 (patch)
tree8db454d9afc0b1964d02781f701719f412d02630 /libnetdata
parentfc8affaabd44aa3f04e2f402dc5e34e04d5c2df4 (diff)
Better ACLK debug communication log (#13281)
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/log/log.c38
-rw-r--r--libnetdata/log/log.h11
2 files changed, 49 insertions, 0 deletions
diff --git a/libnetdata/log/log.c b/libnetdata/log/log.c
index 6f4652e87e..d6793b69bf 100644
--- a/libnetdata/log/log.c
+++ b/libnetdata/log/log.c
@@ -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);
}
@@ -912,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 293901d442..ae86720cbb 100644
--- a/libnetdata/log/log.h
+++ b/libnetdata/log/log.h
@@ -61,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;
@@ -98,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