diff --git a/winpr/include/winpr/wlog.h b/winpr/include/winpr/wlog.h index 87b79c8a2..eda5e60a3 100644 --- a/winpr/include/winpr/wlog.h +++ b/winpr/include/winpr/wlog.h @@ -48,6 +48,7 @@ typedef struct _wLogAppender wLogAppender; #define WLOG_ERROR 4 #define WLOG_FATAL 5 #define WLOG_OFF 6 +#define WLOG_LEVEL_INHERIT 0xFFFF /** * Log Message @@ -198,7 +199,7 @@ struct _wLog WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...); #define WLog_Print(_log, _log_level, _fmt, ...) \ - if (_log_level >= _log->Level) { \ + if (_log_level >= WLog_GetLogLevel(_log)) { \ wLogMessage _log_message; \ _log_message.Type = WLOG_MESSAGE_TEXT; \ _log_message.Level = _log_level; \ @@ -210,7 +211,7 @@ WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...); } #define WLog_Data(_log, _log_level, ...) \ - if (_log_level >= _log->Level) { \ + if (_log_level >= WLog_GetLogLevel(_log)) { \ wLogMessage _log_message; \ _log_message.Type = WLOG_MESSAGE_DATA; \ _log_message.Level = _log_level; \ @@ -222,7 +223,7 @@ WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...); } #define WLog_Image(_log, _log_level, ...) \ - if (_log_level >= _log->Level) { \ + if (_log_level >= WLog_GetLogLevel(_log)) { \ wLogMessage _log_message; \ _log_message.Type = WLOG_MESSAGE_IMAGE; \ _log_message.Level = _log_level; \ @@ -234,7 +235,7 @@ WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...); } #define WLog_Packet(_log, _log_level, ...) \ - if (_log_level >= _log->Level) { \ + if (_log_level >= WLog_GetLogLevel(_log)) { \ wLogMessage _log_message; \ _log_message.Type = WLOG_MESSAGE_PACKET; \ _log_message.Level = _log_level; \ diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.c b/winpr/libwinpr/utils/wlog/BinaryAppender.c index f77b99dbb..f0bd1ba5f 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.c +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.c @@ -122,9 +122,6 @@ int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wL int FunctionNameLength; int TextStringLength; - if (message->Level > log->Level) - return 0; - fp = appender->FileDescriptor; if (!fp) diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index 0b4375a3e..c9ed6bc66 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -68,9 +68,6 @@ int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; - if (message->Level < log->Level) - return 0; - fp = (appender->outputStream == WLOG_CONSOLE_STDERR) ? stderr : stdout; message->PrefixString = prefix; diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index 5acb75256..8904310cb 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -117,9 +117,6 @@ int WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMe FILE* fp; char prefix[WLOG_MAX_PREFIX_SIZE]; - if (message->Level > log->Level) - return 0; - fp = appender->FileDescriptor; if (!fp) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 6df27a5ea..d6a2a9ac4 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -216,14 +216,20 @@ void WLog_PrintMessage(wLog* log, wLogMessage* message, ...) DWORD WLog_GetLogLevel(wLog* log) { - return log->Level; + if (log->Level == WLOG_LEVEL_INHERIT) { + return WLog_GetLogLevel(log->Parent); + } else { + return log->Level; + } } void WLog_SetLogLevel(wLog* log, DWORD logLevel) { - if (logLevel > WLOG_OFF) - logLevel = WLOG_OFF; + if ((logLevel > WLOG_OFF) && (logLevel != WLOG_LEVEL_INHERIT)) + { + logLevel = WLOG_OFF; + } log->Level = logLevel; } @@ -276,7 +282,7 @@ wLog* WLog_New(LPCSTR name , wLog* rootLogger) log->Name = _strdup(name); WLog_ParseName(log, name); - log->Parent = NULL; + log->Parent = rootLogger; log->ChildrenCount = 0; log->ChildrenSize = 16; @@ -285,41 +291,40 @@ wLog* WLog_New(LPCSTR name , wLog* rootLogger) log->Appender = NULL; if (rootLogger) { - log->Level = rootLogger->Level; + log->Level = WLOG_LEVEL_INHERIT; } else { log->Level = WLOG_WARN; - } + nSize = GetEnvironmentVariableA("WLOG_LEVEL", NULL, 0); - nSize = GetEnvironmentVariableA("WLOG_LEVEL", NULL, 0); - - if (nSize) - { - env = (LPSTR) malloc(nSize); - nSize = GetEnvironmentVariableA("WLOG_LEVEL", env, nSize); - - if (env) + if (nSize) { - if (_stricmp(env, "TRACE") == 0) - log->Level = WLOG_TRACE; - else if (_stricmp(env, "DEBUG") == 0) - log->Level = WLOG_DEBUG; - else if (_stricmp(env, "INFO") == 0) - log->Level = WLOG_INFO; - else if (_stricmp(env, "WARN") == 0) - log->Level = WLOG_WARN; - else if (_stricmp(env, "ERROR") == 0) - log->Level = WLOG_ERROR; - else if (_stricmp(env, "FATAL") == 0) - log->Level = WLOG_FATAL; - else if (_stricmp(env, "OFF") == 0) - log->Level = WLOG_OFF; - else if (_strnicmp(env, "0x", 2) == 0) - { - /* TODO: read custom hex value */ - } + env = (LPSTR) malloc(nSize); + nSize = GetEnvironmentVariableA("WLOG_LEVEL", env, nSize); - free(env); + if (env) + { + if (_stricmp(env, "TRACE") == 0) + log->Level = WLOG_TRACE; + else if (_stricmp(env, "DEBUG") == 0) + log->Level = WLOG_DEBUG; + else if (_stricmp(env, "INFO") == 0) + log->Level = WLOG_INFO; + else if (_stricmp(env, "WARN") == 0) + log->Level = WLOG_WARN; + else if (_stricmp(env, "ERROR") == 0) + log->Level = WLOG_ERROR; + else if (_stricmp(env, "FATAL") == 0) + log->Level = WLOG_FATAL; + else if (_stricmp(env, "OFF") == 0) + log->Level = WLOG_OFF; + else if (_strnicmp(env, "0x", 2) == 0) + { + /* TODO: read custom hex value */ + } + + free(env); + } } } }