From 38d3d03e3b598ca560c487a6930b471a096ffac9 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 4 Nov 2024 12:56:14 -0800 Subject: logging: better debug & test logs Don't emit the log for date change unless we are in debug mode. Emit a newline when starting a new NUTS test. Change the default log level - it was too noisy. --- src/core/log.c | 2 +- src/testing/nuts.h | 15 ++++++--------- src/testing/util.c | 8 ++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 9f6a10d6..0084b06e 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -154,7 +154,7 @@ stderr_logger(nng_log_level level, nng_log_facility facility, sgr0 = ""; } - if (timechk && + if (timechk && (log_level >= NNG_LOG_DEBUG) && ((last_log.tm_mday != tm->tm_mday) || (last_log.tm_mon != tm->tm_mon) || (last_log.tm_year != tm->tm_year))) { diff --git a/src/testing/nuts.h b/src/testing/nuts.h index ef639c31..7a60aa32 100644 --- a/src/testing/nuts.h +++ b/src/testing/nuts.h @@ -18,16 +18,17 @@ #define NNG_TESTING_NUTS_H #include +extern void nuts_set_logger(int); extern void nuts_logger( nng_log_level, nng_log_facility, const char *, const char *); // Call nng_fini during test finalization -- this avoids leak warnings. extern void nng_fini(void); #define TEST_FINI nng_fini() -#define TEST_INIT \ - do { \ - nng_log_set_logger(nuts_logger); \ - nng_log_set_level(NNG_LOG_DEBUG); \ +#define TEST_INIT \ + do { \ + nng_log_set_logger(nuts_logger); \ + nng_log_set_level(NNG_LOG_NONE); \ } while (0) #include "acutest.h" @@ -211,11 +212,7 @@ extern const char *nuts_garbled_crt; #define NUTS_PROTO(x, y) (((x) << 4u) | (y)) -#define NUTS_ENABLE_LOG(level) \ - do { \ - nng_log_set_logger(nng_stderr_logger); \ - nng_log_set_level(level); \ - } while (0) +#define NUTS_ENABLE_LOG(level) nuts_set_logger(level) #define NUTS_LOGGING() \ do { \ diff --git a/src/testing/util.c b/src/testing/util.c index 523fd1cd..497598ed 100644 --- a/src/testing/util.c +++ b/src/testing/util.c @@ -171,6 +171,14 @@ nuts_sleep(int msec) #define NUTS_COLOR_GREEN_INTENSIVE_ 4 #define NUTS_COLOR_RED_INTENSIVE_ 5 +void +nuts_set_logger(int level) +{ + printf("\n"); // force a new line + nng_log_set_logger(nng_stderr_logger); + nng_log_set_level(level); +} + void nuts_logger(nng_log_level level, nng_log_facility fac, const char *msgid, const char *msg) -- cgit v1.2.3-70-g09d2