From e9bc54e8b7b0e79d1b14c4e2edd765da3385ff90 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sat, 11 Mar 2023 09:33:26 +0100 Subject: [PATCH] [core] improve logging in freerdp_set_last_error --- include/freerdp/freerdp.h | 3 ++- libfreerdp/core/freerdp.c | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 1075a8da8..18ddb23d8 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -614,7 +614,8 @@ owned by rdpRdp */ FREERDP_API const char* freerdp_get_last_error_string(UINT32 error); FREERDP_API const char* freerdp_get_last_error_category(UINT32 error); - FREERDP_API void freerdp_set_last_error(rdpContext* context, UINT32 lastError); +#define freerdp_set_last_error(context, lastError) \ + freerdp_set_last_error_ex((context), (lastError), __FUNCTION__, __FILE__, __LINE__) #define freerdp_set_last_error_if_not(context, lastError) \ do \ diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 94b763ad2..95350b101 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -990,31 +990,41 @@ const char* freerdp_get_last_error_category(UINT32 code) return string; } -void freerdp_set_last_error(rdpContext* context, UINT32 lastError) -{ - freerdp_set_last_error_ex(context, lastError, NULL, NULL, -1); -} - void freerdp_set_last_error_ex(rdpContext* context, UINT32 lastError, const char* fkt, const char* file, int line) { + static wLog* _log = NULL; + if (_log) + _log = WLog_Get(TAG); + WINPR_ASSERT(context); if (lastError) - WLog_ERR(TAG, "%s %s [0x%08" PRIX32 "]", fkt, freerdp_get_last_error_name(lastError), - lastError); + { + if (WLog_IsLevelActive(_log, WLOG_ERROR)) + { + WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, WLOG_ERROR, line, file, fkt, + "%s [0x%08" PRIX32 "]", freerdp_get_last_error_name(lastError), + lastError); + } + } if (lastError == FREERDP_ERROR_SUCCESS) { - WLog_DBG(TAG, "%s resetting error state", fkt); + if (WLog_IsLevelActive(_log, WLOG_DEBUG)) + WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, WLOG_DEBUG, line, file, fkt, + "resetting error state"); } else if (context->LastError != FREERDP_ERROR_SUCCESS) { - WLog_ERR(TAG, "%s: TODO: Trying to set error code %s, but %s already set!", fkt, - freerdp_get_last_error_name(lastError), - freerdp_get_last_error_name(context->LastError)); + if (WLog_IsLevelActive(_log, WLOG_ERROR)) + { + WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, WLOG_ERROR, line, file, fkt, + "TODO: Trying to set error code %s, but %s already set!", + freerdp_get_last_error_name(lastError), + freerdp_get_last_error_name(context->LastError)); + } } - context->LastError = lastError; }