From 00c172034d963029d017d89efaddec6487f4a319 Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 12 Jan 2023 10:38:00 -0500 Subject: [PATCH] log level changes with INFO level --- library/utils.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/library/utils.c b/library/utils.c index 213b6021..c84c780d 100644 --- a/library/utils.c +++ b/library/utils.c @@ -129,13 +129,11 @@ static void init_uv_mbed_log(); void ziti_log_init(uv_loop_t *loop, int level, log_writer log_func) { init_uv_mbed_log(); - if (level == ZITI_LOG_DEFAULT_LEVEL) { - level = ziti_log_lvl; - } // in case it was set before - init_debug(loop); - ziti_log_set_level(level, NULL); + if (level == ZITI_LOG_DEFAULT_LEVEL) { + level = ziti_log_lvl; + } if (log_func == NULL) { // keep the logger if it was already set @@ -143,9 +141,17 @@ void ziti_log_init(uv_loop_t *loop, int level, log_writer log_func) { } else { ziti_log_set_logger(log_func); } + + ziti_log_set_level(level, NULL); } void ziti_log_set_level(int level, const char *marker) { + if (level > TRACE) { + level = TRACE; + } else if (level < 0) { + level = ZITI_LOG_DEFAULT_LEVEL; + } + if (level == ZITI_LOG_DEFAULT_LEVEL) { if (marker) { model_map_remove(&log_levels, marker); @@ -162,9 +168,9 @@ void ziti_log_set_level(int level, const char *marker) { } if (logger) { - char msg[128]; - int len = snprintf(msg, sizeof(msg), "set log level: %s=%d", marker ? marker : "root", level); - logger(INFO, "ziti_log_set_level", msg, len); + int l = level == ZITI_LOG_DEFAULT_LEVEL ? ziti_log_lvl : level; + const char *lbl = level_labels[l]; + ZITI_LOG(INFO, "set log level: %s=%d/%s", marker ? marker : "root", l, lbl); } }