[core] improve logging in freerdp_set_last_error

This commit is contained in:
Armin Novak
2023-03-11 09:33:26 +01:00
committed by Martin Fleisz
parent 39b3847428
commit e9bc54e8b7
2 changed files with 24 additions and 13 deletions

View File

@@ -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 \

View File

@@ -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;
}