From 158402ab03da1349c27c815a8fff48a1f4ce25e1 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 31 Jul 2023 13:20:14 +0200 Subject: [PATCH] Add logging prefixes to api.c client and server --- tests/api.c | 9 +++++++++ wolfcrypt/src/logging.c | 15 ++++++++++++++- wolfssl/wolfcrypt/logging.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index ed54dd6af..db12aed66 100644 --- a/tests/api.c +++ b/tests/api.c @@ -6152,6 +6152,8 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args) size_t msg_len = 0; #endif + wolfSSL_SetLoggingPrefix("server"); + #ifdef WOLFSSL_TIRTOS fdOpenSession(Task_self()); #endif @@ -6442,6 +6444,8 @@ done: #endif } + wolfSSL_SetLoggingPrefix(NULL); + #ifndef WOLFSSL_TIRTOS return 0; #endif @@ -6688,6 +6692,8 @@ static int test_client_nofail(void* args, cbType cb) int doUdp = 0; const char* cipherName1, *cipherName2; + wolfSSL_SetLoggingPrefix("client"); + #ifdef WOLFSSL_TIRTOS fdOpenSession(Task_self()); #endif @@ -6907,6 +6913,9 @@ done: (void)args; (void)cb; #endif /* !NO_WOLFSSL_CLIENT */ + + wolfSSL_SetLoggingPrefix(NULL); + return 0; } diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index 080d9a678..eacc6b09d 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -127,6 +127,7 @@ THREAD_LS_T void *StackSizeCheck_stackOffsetPointer = 0; /* Set these to default values initially. */ static wolfSSL_Logging_cb log_function = NULL; static int loggingEnabled = 0; +THREAD_LS_T const char* log_prefix = NULL; #if defined(WOLFSSL_APACHE_MYNEWT) #include "log/log.h" @@ -186,6 +187,15 @@ void wolfSSL_Debugging_OFF(void) #endif } +WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix) +{ +#ifdef DEBUG_WOLFSSL + log_prefix = prefix; +#else + (void)prefix; +#endif +} + #ifdef WOLFSSL_FUNC_TIME /* WARNING: This code is only to be used for debugging performance. * The code is not thread-safe. @@ -316,7 +326,10 @@ static void wolfssl_log(const int logLevel, const char *const logMessage) defined(HAVE_STACK_SIZE_VERBOSE) && defined(HAVE_STACK_SIZE_VERBOSE_LOG) STACK_SIZE_CHECKPOINT_MSG(logMessage); #else - fprintf(stderr, "%s\n", logMessage); + if (log_prefix != NULL) + fprintf(stderr, "[%s]: %s\n", log_prefix, logMessage); + else + fprintf(stderr, "%s\n", logMessage); #endif } } diff --git a/wolfssl/wolfcrypt/logging.h b/wolfssl/wolfcrypt/logging.h index 914667266..f074382c2 100644 --- a/wolfssl/wolfcrypt/logging.h +++ b/wolfssl/wolfcrypt/logging.h @@ -100,6 +100,8 @@ WOLFSSL_API int wolfSSL_Debugging_ON(void); /* turn logging off */ WOLFSSL_API void wolfSSL_Debugging_OFF(void); +WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix); + #ifdef HAVE_WC_INTROSPECTION WOLFSSL_API const char *wolfSSL_configure_args(void); WOLFSSL_API const char *wolfSSL_global_cflags(void);