From add66e8fb93f7c13021e6b45ddccfcb6aa3e7214 Mon Sep 17 00:00:00 2001 From: xinyi-xs Date: Tue, 25 Jun 2024 15:01:36 +0800 Subject: [PATCH] * NEW [env] support uds env && fixed log_to related env. Signed-off-by: xinyi-xs --- include/nng/supplemental/nanolib/env.h | 1 + src/supplemental/nanolib/env.c | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/nng/supplemental/nanolib/env.h b/include/nng/supplemental/nanolib/env.h index ebd0ddc29..fe3e9a57c 100644 --- a/include/nng/supplemental/nanolib/env.h +++ b/include/nng/supplemental/nanolib/env.h @@ -45,6 +45,7 @@ #define NANOMQ_LOG_LEVEL "NANOMQ_LOG_LEVEL" #define NANOMQ_LOG_TO "NANOMQ_LOG_TO" +#define NANOMQ_LOG_UDS_ADDR "NANOMQ_LOG_UDS_ADDR" #define NANOMQ_LOG_DIR "NANOMQ_LOG_DIR" #define NANOMQ_LOG_FILE "NANOMQ_LOG_FILE" #define NANOMQ_LOG_ROTATION_SIZE "NANOMQ_LOG_ROTATION_SIZE" diff --git a/src/supplemental/nanolib/env.c b/src/supplemental/nanolib/env.c index b22314055..b6e24f919 100644 --- a/src/supplemental/nanolib/env.c +++ b/src/supplemental/nanolib/env.c @@ -89,6 +89,17 @@ set_log_level(conf_log *log) nng_strfree(level); } +static void +set_log_uds_addr(conf_log *log) +{ + char *uds_addr = NULL; + set_string_var(&uds_addr, NANOMQ_LOG_UDS_ADDR); + if (uds_addr != NULL) { + log->uds_addr = nng_strdup(uds_addr); + } + nng_strfree(uds_addr); +} + static void set_log_rotation_size(conf_log *log) { @@ -118,15 +129,21 @@ set_log_to(conf_log *log) char *log_to = NULL; set_string_var(&log_to, NANOMQ_LOG_TO); if (log_to) { - if (!strstr(log_to, "file")) { + if (strstr(log_to, "file")) { log->type |= LOG_TO_FILE; } - if (!strstr(log_to, "console")) { + if (strstr(log_to, "console")) { log->type |= LOG_TO_CONSOLE; } - if (!strstr(log_to, "syslog")) { + if (strstr(log_to, "syslog")) { log->type |= LOG_TO_SYSLOG; } + if (strstr(log_to, "uds")) { + log->type |= LOG_TO_UDS; + if (log->uds_addr == NULL) { + fprintf(stderr, "uds addr is NULL"); + } + } } nng_strfree(log_to); } @@ -202,6 +219,7 @@ read_env_conf(conf *config) #if defined(ENABLE_LOG) set_log_level(&config->log); set_log_rotation_size(&config->log); + set_log_uds_addr(&config->log); set_log_to(&config->log); set_string_var(&config->log.dir, NANOMQ_LOG_DIR); set_string_var(&config->log.file, NANOMQ_LOG_FILE);