Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support uds env && fixed log_to related env errors. #990

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nng/supplemental/nanolib/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 21 additions & 3 deletions src/supplemental/nanolib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Loading