Fix #5024: Update inherited log level for all child loggers when setting a new one.
This commit is contained in:
parent
b216520d5b
commit
37a01a19d8
@ -110,9 +110,26 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
DWORD line,
|
||||
const char* file, const char* function, va_list args);
|
||||
|
||||
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
||||
|
||||
static INLINE BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level)
|
||||
{
|
||||
DWORD level;
|
||||
|
||||
if (!_log)
|
||||
return FALSE;
|
||||
|
||||
level = WLog_GetLogLevel(_log);
|
||||
|
||||
if (level == WLOG_OFF)
|
||||
return FALSE;
|
||||
|
||||
return _log_level >= level;
|
||||
}
|
||||
|
||||
#define WLog_Print(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
if (WLog_IsLevelActive(_log, _log_level)) { \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
@ -120,7 +137,7 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
|
||||
#define WLog_PrintVA(_log, _log_level, _args) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
if (WLog_IsLevelActive(_log, _log_level)) { \
|
||||
WLog_PrintMessageVA(_log, WLOG_MESSAGE_TEXT, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, _args ); \
|
||||
} \
|
||||
@ -128,7 +145,7 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
|
||||
#define WLog_Data(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
if (WLog_IsLevelActive(_log, _log_level)) { \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
@ -136,7 +153,7 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
|
||||
#define WLog_Image(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
if (WLog_IsLevelActive(_log, _log_level)) { \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
@ -144,7 +161,7 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
|
||||
#define WLog_Packet(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
if (WLog_IsLevelActive(_log, _log_level)) { \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
@ -158,16 +175,10 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
#define WLog_ERR(tag, ...) WLog_Print(WLog_Get(tag), WLOG_ERROR, __VA_ARGS__)
|
||||
#define WLog_FATAL(tag, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, __VA_ARGS__)
|
||||
|
||||
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
||||
WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
|
||||
WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level);
|
||||
WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter);
|
||||
|
||||
static INLINE BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level)
|
||||
{
|
||||
return _log ? _log_level >= WLog_GetLogLevel(_log) : FALSE;
|
||||
}
|
||||
|
||||
WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
|
||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_OpenAppender(wLog* log);
|
||||
|
@ -420,11 +420,14 @@ BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line,
|
||||
|
||||
DWORD WLog_GetLogLevel(wLog* log)
|
||||
{
|
||||
if (!log)
|
||||
return WLOG_OFF;
|
||||
|
||||
if (log->FilterLevel < 0)
|
||||
log->FilterLevel = WLog_GetFilterLogLevel(log);
|
||||
|
||||
if ((log->FilterLevel >= 0) && (log->FilterLevel != WLOG_LEVEL_INHERIT))
|
||||
return log->FilterLevel;
|
||||
if (log->FilterLevel >= 0)
|
||||
return (DWORD)log->FilterLevel;
|
||||
else if (log->Level == WLOG_LEVEL_INHERIT)
|
||||
log->Level = WLog_GetLogLevel(log->Parent);
|
||||
|
||||
@ -443,7 +446,7 @@ BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level)
|
||||
if (lvl < 0)
|
||||
return FALSE;
|
||||
|
||||
return WLog_SetLogLevel(log, lvl);
|
||||
return WLog_SetLogLevel(log, (DWORD)lvl);
|
||||
}
|
||||
|
||||
BOOL WLog_AddStringLogFilters(LPCSTR filter)
|
||||
@ -515,8 +518,32 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UpdateInheritLevel(wLog* log, DWORD logLevel)
|
||||
{
|
||||
if (!log)
|
||||
return FALSE;
|
||||
|
||||
if (log->inherit)
|
||||
{
|
||||
DWORD x;
|
||||
log->Level = logLevel;
|
||||
|
||||
for (x = 0; x < log->ChildrenCount; x++)
|
||||
{
|
||||
wLog* child = log->Children[x];
|
||||
|
||||
if (!WLog_UpdateInheritLevel(child, logLevel))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel)
|
||||
{
|
||||
DWORD x;
|
||||
|
||||
if (!log)
|
||||
return FALSE;
|
||||
|
||||
@ -524,6 +551,16 @@ BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel)
|
||||
logLevel = WLOG_OFF;
|
||||
|
||||
log->Level = logLevel;
|
||||
log->inherit = (logLevel == WLOG_LEVEL_INHERIT) ? TRUE : FALSE;
|
||||
|
||||
for (x = 0; x < log->ChildrenCount; x++)
|
||||
{
|
||||
wLog* child = log->Children[x];
|
||||
|
||||
if (!WLog_UpdateInheritLevel(child, logLevel))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -695,7 +732,7 @@ LONG WLog_GetFilterLogLevel(wLog* log)
|
||||
if (match)
|
||||
log->FilterLevel = g_Filters[i].Level;
|
||||
else
|
||||
log->FilterLevel = WLOG_LEVEL_INHERIT;
|
||||
log->FilterLevel = -1;
|
||||
|
||||
return log->FilterLevel;
|
||||
}
|
||||
@ -777,6 +814,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
if (rootLogger)
|
||||
{
|
||||
log->Level = WLOG_LEVEL_INHERIT;
|
||||
log->inherit = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -802,14 +840,20 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
free(env);
|
||||
|
||||
if (iLevel >= 0)
|
||||
log->Level = (DWORD) iLevel;
|
||||
{
|
||||
if (!WLog_SetLogLevel(log, (DWORD) iLevel))
|
||||
goto out_fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iLevel = WLog_GetFilterLogLevel(log);
|
||||
|
||||
if ((iLevel >= 0) && (iLevel != WLOG_LEVEL_INHERIT))
|
||||
log->Level = (DWORD) iLevel;
|
||||
if (iLevel >= 0)
|
||||
{
|
||||
if (!WLog_SetLogLevel(log, (DWORD) iLevel))
|
||||
goto out_fail;
|
||||
}
|
||||
|
||||
return log;
|
||||
out_fail:
|
||||
|
@ -67,6 +67,7 @@ struct _wLog
|
||||
DWORD Level;
|
||||
|
||||
BOOL IsRoot;
|
||||
BOOL inherit;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
wLogAppender* Appender;
|
||||
|
Loading…
Reference in New Issue
Block a user