From 56507ab5c4db009be5251bde832f594fe5ed3d5e Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 21 Apr 2024 12:23:07 -0700 Subject: Logging improvements (#1816) * Add nng_str_sockaddr to get string representation of socket address. * Added nng_log_get_level() is meant to allow users to obtain the current level and avoid some possibly expensive operations just to collect debugging information when debugging is not in effect. We use a custom logger for NUTS, and this fits within the NUTS test framework well, so that if -v is supplied we get more content. All tests now get this by default. --- src/testing/nuts.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/testing/nuts.h') diff --git a/src/testing/nuts.h b/src/testing/nuts.h index f24f7136..da0f525f 100644 --- a/src/testing/nuts.h +++ b/src/testing/nuts.h @@ -17,9 +17,18 @@ #ifndef NNG_TESTING_NUTS_H #define NNG_TESTING_NUTS_H +#include +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); \ + } while (0) #include "acutest.h" #include @@ -27,7 +36,6 @@ extern void nng_fini(void); #include // The following headers are provided for test code convenience. -#include #include #include #include @@ -210,6 +218,11 @@ extern const char *nuts_garbled_crt; nng_log_set_level(level); \ } while (0) +#define NUTS_LOGGING() \ + do { \ + nng_log_set_logger(nuts_logger); \ + nng_log_set_level(NNG_LOG_DEBUG); \ + } while (0) #ifdef __cplusplus }; #endif -- cgit v1.2.3-70-g09d2