diff --git a/includes/ziti/ziti_log.h b/includes/ziti/ziti_log.h index 8c06203c..41b67eff 100644 --- a/includes/ziti/ziti_log.h +++ b/includes/ziti/ziti_log.h @@ -40,7 +40,7 @@ enum DebugLevel { }; #define ZITI_LOG(level, fmt, ...) do { \ -if (level <= ziti_log_level) { ziti_logger(level, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__); }\ +if (level <= ziti_log_level()) { ziti_logger(level, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__); }\ } while(0) #ifdef __cplusplus @@ -65,7 +65,7 @@ ZITI_FUNC extern void ziti_log_set_logger(log_writer logger); ZITI_FUNC extern void ziti_log_set_level(int level); // don't use directly -ZITI_FUNC extern int ziti_log_level; +ZITI_FUNC extern int ziti_log_level(); #ifdef __cplusplus } diff --git a/library/utils.c b/library/utils.c index f6c831e9..6317f432 100644 --- a/library/utils.c +++ b/library/utils.c @@ -99,7 +99,7 @@ const char* ziti_git_commit() { return to_str(ZITI_COMMIT); } -int ziti_log_level = ZITI_LOG_DEFAULT_LEVEL; +static int ziti_log_lvl = ZITI_LOG_DEFAULT_LEVEL; static FILE *ziti_debug_out; static bool log_initialized = false; @@ -128,7 +128,7 @@ void ziti_log_init(uv_loop_t *loop, int level, log_writer log_func) { init_debug(loop); if (level == ZITI_LOG_DEFAULT_LEVEL) - level = ziti_log_level; // in case it was set before + level = ziti_log_lvl; // in case it was set before ziti_log_set_level(level); @@ -144,15 +144,19 @@ void ziti_log_set_level(int level) { if (level == ZITI_LOG_DEFAULT_LEVEL) { char *lvl = getenv("ZITI_LOG"); if (lvl != NULL) { - ziti_log_level = (int) strtol(lvl, NULL, 10); + ziti_log_lvl = (int) strtol(lvl, NULL, 10); } else { - ziti_log_level = INFO; + ziti_log_lvl = INFO; } } else { - ziti_log_level = level; + ziti_log_lvl = level; } - uv_mbed_set_debug(ziti_log_level, uv_mbed_logger); + uv_mbed_set_debug(ziti_log_lvl, uv_mbed_logger); +} + +int ziti_log_level() { + return ziti_log_lvl; } void ziti_log_set_logger(log_writer log) { @@ -170,7 +174,7 @@ static void init_debug(uv_loop_t *loop) { } ts_loop = loop; log_initialized = true; - ziti_log_set_level(ziti_log_level); + ziti_log_set_level(ziti_log_lvl); ziti_debug_out = stderr; starttime = uv_now(loop); @@ -277,7 +281,7 @@ int lt_zero(int v) { return v < 0; } int non_zero(int v) { return v != 0; } void hexDump (char *desc, void *addr, int len) { - if (DEBUG > ziti_log_level) return; + if (DEBUG > ziti_log_level()) return; ZITI_LOG(DEBUG, " "); int i; unsigned char buffLine[17]; diff --git a/library/ziti_enroll.c b/library/ziti_enroll.c index e389a5dc..42651aec 100644 --- a/library/ziti_enroll.c +++ b/library/ziti_enroll.c @@ -106,7 +106,7 @@ int ziti_enroll(ziti_enroll_opts *opts, uv_loop_t *loop, ziti_enroll_cb enroll_c ecfg->private_key = opts->enroll_key; TRY(ziti, load_jwt(opts->jwt, ecfg, &ecfg->zejh, &ecfg->zej)); - if (DEBUG <= ziti_log_level) { + if (DEBUG <= ziti_log_level()) { dump_ziti_enrollment_jwt_header(ecfg->zejh, 0); dump_ziti_enrollment_jwt(ecfg->zej, 0); }