mirror of https://github.com/FreeRDP/FreeRDP
Merge pull request #24 from MartinHaimberger/wlogimprovment
improved WLog
This commit is contained in:
commit
9668549fa4
|
@ -93,7 +93,7 @@ struct _COMMAND_LINE_ARGUMENT_A
|
|||
LPCSTR Name;
|
||||
DWORD Flags;
|
||||
LPCSTR Format;
|
||||
LPSTR Default;
|
||||
LPCSTR Default;
|
||||
LPSTR Value;
|
||||
LONG Index;
|
||||
LPCSTR Alias;
|
||||
|
|
|
@ -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; \
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue