Skip to content

Commit

Permalink
ziti_log_level()
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoby committed Dec 18, 2020
1 parent de129da commit 320e02b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions includes/ziti/ziti_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
20 changes: 12 additions & 8 deletions library/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion library/ziti_enroll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 320e02b

Please sign in to comment.