Added recursion guard to logging functions.
This commit is contained in:
parent
763410a66d
commit
c32c48fbb6
@ -33,14 +33,14 @@ extern "C" {
|
|||||||
#include <winpr/synch.h>
|
#include <winpr/synch.h>
|
||||||
#include <winpr/thread.h>
|
#include <winpr/thread.h>
|
||||||
|
|
||||||
typedef struct _wLog wLog;
|
typedef struct _wLog wLog;
|
||||||
typedef struct _wLogMessage wLogMessage;
|
typedef struct _wLogMessage wLogMessage;
|
||||||
typedef struct _wLogLayout wLogLayout;
|
typedef struct _wLogLayout wLogLayout;
|
||||||
typedef struct _wLogAppender wLogAppender;
|
typedef struct _wLogAppender wLogAppender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log Levels
|
* Log Levels
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define WLOG_TRACE 0
|
#define WLOG_TRACE 0
|
||||||
#define WLOG_DEBUG 1
|
#define WLOG_DEBUG 1
|
||||||
@ -51,63 +51,63 @@ typedef struct _wLogAppender wLogAppender;
|
|||||||
#define WLOG_OFF 6
|
#define WLOG_OFF 6
|
||||||
#define WLOG_LEVEL_INHERIT 0xFFFF
|
#define WLOG_LEVEL_INHERIT 0xFFFF
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log Message
|
* Log Message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define WLOG_MESSAGE_TEXT 0
|
#define WLOG_MESSAGE_TEXT 0
|
||||||
#define WLOG_MESSAGE_DATA 1
|
#define WLOG_MESSAGE_DATA 1
|
||||||
#define WLOG_MESSAGE_IMAGE 2
|
#define WLOG_MESSAGE_IMAGE 2
|
||||||
#define WLOG_MESSAGE_PACKET 3
|
#define WLOG_MESSAGE_PACKET 3
|
||||||
|
|
||||||
struct _wLogMessage
|
struct _wLogMessage
|
||||||
{
|
{
|
||||||
DWORD Type;
|
DWORD Type;
|
||||||
|
|
||||||
DWORD Level;
|
DWORD Level;
|
||||||
|
|
||||||
LPSTR PrefixString;
|
LPSTR PrefixString;
|
||||||
|
|
||||||
LPCSTR FormatString;
|
LPCSTR FormatString;
|
||||||
LPSTR TextString;
|
LPSTR TextString;
|
||||||
|
|
||||||
DWORD LineNumber; /* __LINE__ */
|
DWORD LineNumber; /* __LINE__ */
|
||||||
LPCSTR FileName; /* __FILE__ */
|
LPCSTR FileName; /* __FILE__ */
|
||||||
LPCSTR FunctionName; /* __FUNCTION__ */
|
LPCSTR FunctionName; /* __FUNCTION__ */
|
||||||
|
|
||||||
/* Data Message */
|
/* Data Message */
|
||||||
|
|
||||||
void* Data;
|
void* Data;
|
||||||
int Length;
|
int Length;
|
||||||
|
|
||||||
/* Image Message */
|
/* Image Message */
|
||||||
|
|
||||||
void* ImageData;
|
void* ImageData;
|
||||||
int ImageWidth;
|
int ImageWidth;
|
||||||
int ImageHeight;
|
int ImageHeight;
|
||||||
int ImageBpp;
|
int ImageBpp;
|
||||||
|
|
||||||
/* Packet Message */
|
/* Packet Message */
|
||||||
|
|
||||||
void* PacketData;
|
void* PacketData;
|
||||||
int PacketLength;
|
int PacketLength;
|
||||||
DWORD PacketFlags;
|
DWORD PacketFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log Layout
|
* Log Layout
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct _wLogLayout
|
struct _wLogLayout
|
||||||
{
|
{
|
||||||
DWORD Type;
|
DWORD Type;
|
||||||
|
|
||||||
LPSTR FormatString;
|
LPSTR FormatString;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log Appenders
|
* Log Appenders
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define WLOG_APPENDER_CONSOLE 0
|
#define WLOG_APPENDER_CONSOLE 0
|
||||||
#define WLOG_APPENDER_FILE 1
|
#define WLOG_APPENDER_FILE 1
|
||||||
@ -116,18 +116,19 @@ struct _wLogLayout
|
|||||||
#define WLOG_PACKET_INBOUND 1
|
#define WLOG_PACKET_INBOUND 1
|
||||||
#define WLOG_PACKET_OUTBOUND 2
|
#define WLOG_PACKET_OUTBOUND 2
|
||||||
|
|
||||||
typedef int (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
|
typedef int (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
|
||||||
typedef int (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
|
typedef int (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
|
||||||
typedef int (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
typedef int (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||||
typedef int (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
typedef int (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||||
typedef int (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
typedef int (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||||
typedef int (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
typedef int (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||||
|
|
||||||
#define WLOG_APPENDER_COMMON() \
|
#define WLOG_APPENDER_COMMON() \
|
||||||
DWORD Type; \
|
DWORD Type; \
|
||||||
DWORD State; \
|
DWORD State; \
|
||||||
wLogLayout* Layout; \
|
wLogLayout* Layout; \
|
||||||
CRITICAL_SECTION lock; \
|
CRITICAL_SECTION lock; \
|
||||||
|
BOOL recursive; \
|
||||||
void* TextMessageContext; \
|
void* TextMessageContext; \
|
||||||
void* DataMessageContext; \
|
void* DataMessageContext; \
|
||||||
void* ImageMessageContext; \
|
void* ImageMessageContext; \
|
||||||
@ -139,79 +140,79 @@ typedef int (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* ap
|
|||||||
WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \
|
WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \
|
||||||
WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage
|
WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage
|
||||||
|
|
||||||
struct _wLogAppender
|
struct _wLogAppender
|
||||||
{
|
{
|
||||||
WLOG_APPENDER_COMMON();
|
WLOG_APPENDER_COMMON();
|
||||||
};
|
};
|
||||||
|
|
||||||
#define WLOG_CONSOLE_STDOUT 1
|
#define WLOG_CONSOLE_STDOUT 1
|
||||||
#define WLOG_CONSOLE_STDERR 2
|
#define WLOG_CONSOLE_STDERR 2
|
||||||
#define WLOG_CONSOLE_DEBUG 3
|
#define WLOG_CONSOLE_DEBUG 3
|
||||||
|
|
||||||
struct _wLogConsoleAppender
|
struct _wLogConsoleAppender
|
||||||
{
|
{
|
||||||
WLOG_APPENDER_COMMON();
|
WLOG_APPENDER_COMMON();
|
||||||
|
|
||||||
int outputStream;
|
int outputStream;
|
||||||
};
|
};
|
||||||
typedef struct _wLogConsoleAppender wLogConsoleAppender;
|
typedef struct _wLogConsoleAppender wLogConsoleAppender;
|
||||||
|
|
||||||
struct _wLogFileAppender
|
struct _wLogFileAppender
|
||||||
{
|
{
|
||||||
WLOG_APPENDER_COMMON();
|
WLOG_APPENDER_COMMON();
|
||||||
|
|
||||||
char* FileName;
|
char* FileName;
|
||||||
char* FilePath;
|
char* FilePath;
|
||||||
char* FullFileName;
|
char* FullFileName;
|
||||||
FILE* FileDescriptor;
|
FILE* FileDescriptor;
|
||||||
};
|
};
|
||||||
typedef struct _wLogFileAppender wLogFileAppender;
|
typedef struct _wLogFileAppender wLogFileAppender;
|
||||||
|
|
||||||
struct _wLogBinaryAppender
|
struct _wLogBinaryAppender
|
||||||
{
|
{
|
||||||
WLOG_APPENDER_COMMON();
|
WLOG_APPENDER_COMMON();
|
||||||
|
|
||||||
char* FileName;
|
char* FileName;
|
||||||
char* FilePath;
|
char* FilePath;
|
||||||
char* FullFileName;
|
char* FullFileName;
|
||||||
FILE* FileDescriptor;
|
FILE* FileDescriptor;
|
||||||
};
|
};
|
||||||
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter
|
* Filter
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct _wLogFilter
|
struct _wLogFilter
|
||||||
{
|
{
|
||||||
DWORD Level;
|
DWORD Level;
|
||||||
LPSTR* Names;
|
LPSTR* Names;
|
||||||
DWORD NameCount;
|
DWORD NameCount;
|
||||||
};
|
};
|
||||||
typedef struct _wLogFilter wLogFilter;
|
typedef struct _wLogFilter wLogFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logger
|
* Logger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct _wLog
|
struct _wLog
|
||||||
{
|
{
|
||||||
LPSTR Name;
|
LPSTR Name;
|
||||||
DWORD Level;
|
DWORD Level;
|
||||||
|
|
||||||
BOOL IsRoot;
|
BOOL IsRoot;
|
||||||
LPSTR* Names;
|
LPSTR* Names;
|
||||||
DWORD NameCount;
|
DWORD NameCount;
|
||||||
wLogAppender* Appender;
|
wLogAppender* Appender;
|
||||||
|
|
||||||
wLog* Parent;
|
wLog* Parent;
|
||||||
wLog** Children;
|
wLog** Children;
|
||||||
DWORD ChildrenCount;
|
DWORD ChildrenCount;
|
||||||
DWORD ChildrenSize;
|
DWORD ChildrenSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
|
WINPR_API void WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
|
||||||
WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
|
WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
|
||||||
|
|
||||||
#define WLog_Print(_log, _log_level, _fmt, ...) \
|
#define WLog_Print(_log, _log_level, _fmt, ...) \
|
||||||
if (_log_level >= WLog_GetLogLevel(_log)) { \
|
if (_log_level >= WLog_GetLogLevel(_log)) { \
|
||||||
@ -276,28 +277,28 @@ WINPR_API int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
|||||||
#define WLog_IsLevelActive(_log, _log_level) \
|
#define WLog_IsLevelActive(_log, _log_level) \
|
||||||
(_log_level >= WLog_GetLogLevel(_log))
|
(_log_level >= WLog_GetLogLevel(_log))
|
||||||
|
|
||||||
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
||||||
WINPR_API void WLog_SetLogLevel(wLog* log, DWORD logLevel);
|
WINPR_API void WLog_SetLogLevel(wLog* log, DWORD logLevel);
|
||||||
|
|
||||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||||
WINPR_API void WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
|
WINPR_API void WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
|
||||||
|
|
||||||
WINPR_API int WLog_OpenAppender(wLog* log);
|
WINPR_API int WLog_OpenAppender(wLog* log);
|
||||||
WINPR_API int WLog_CloseAppender(wLog* log);
|
WINPR_API int WLog_CloseAppender(wLog* log);
|
||||||
|
|
||||||
WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
|
WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
|
||||||
|
|
||||||
WINPR_API void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
|
WINPR_API void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
|
||||||
WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
|
WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
|
||||||
|
|
||||||
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
|
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
|
||||||
WINPR_API void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
|
WINPR_API void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
|
||||||
|
|
||||||
WINPR_API wLog* WLog_GetRoot(void);
|
WINPR_API wLog* WLog_GetRoot(void);
|
||||||
WINPR_API wLog* WLog_Get(LPCSTR name);
|
WINPR_API wLog* WLog_Get(LPCSTR name);
|
||||||
|
|
||||||
WINPR_API void WLog_Init(void);
|
WINPR_API void WLog_Init(void);
|
||||||
WINPR_API void WLog_Uninit(void);
|
WINPR_API void WLog_Uninit(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,6 @@ int WLog_Write(wLog* log, wLogMessage* message)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
wLogAppender* appender;
|
wLogAppender* appender;
|
||||||
|
|
||||||
appender = WLog_GetLogAppender(log);
|
appender = WLog_GetLogAppender(log);
|
||||||
|
|
||||||
if (!appender)
|
if (!appender)
|
||||||
@ -74,10 +73,13 @@ int WLog_Write(wLog* log, wLogMessage* message)
|
|||||||
|
|
||||||
EnterCriticalSection(&appender->lock);
|
EnterCriticalSection(&appender->lock);
|
||||||
|
|
||||||
|
if (appender->recursive)
|
||||||
|
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||||
|
|
||||||
|
appender->recursive = TRUE;
|
||||||
status = appender->WriteMessage(log, appender, message);
|
status = appender->WriteMessage(log, appender, message);
|
||||||
|
appender->recursive = FALSE;
|
||||||
LeaveCriticalSection(&appender->lock);
|
LeaveCriticalSection(&appender->lock);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +87,6 @@ int WLog_WriteData(wLog* log, wLogMessage* message)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
wLogAppender* appender;
|
wLogAppender* appender;
|
||||||
|
|
||||||
appender = WLog_GetLogAppender(log);
|
appender = WLog_GetLogAppender(log);
|
||||||
|
|
||||||
if (!appender)
|
if (!appender)
|
||||||
@ -99,10 +100,13 @@ int WLog_WriteData(wLog* log, wLogMessage* message)
|
|||||||
|
|
||||||
EnterCriticalSection(&appender->lock);
|
EnterCriticalSection(&appender->lock);
|
||||||
|
|
||||||
|
if (appender->recursive)
|
||||||
|
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||||
|
|
||||||
|
appender->recursive = TRUE;
|
||||||
status = appender->WriteDataMessage(log, appender, message);
|
status = appender->WriteDataMessage(log, appender, message);
|
||||||
|
appender->recursive = FALSE;
|
||||||
LeaveCriticalSection(&appender->lock);
|
LeaveCriticalSection(&appender->lock);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +114,6 @@ int WLog_WriteImage(wLog* log, wLogMessage* message)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
wLogAppender* appender;
|
wLogAppender* appender;
|
||||||
|
|
||||||
appender = WLog_GetLogAppender(log);
|
appender = WLog_GetLogAppender(log);
|
||||||
|
|
||||||
if (!appender)
|
if (!appender)
|
||||||
@ -124,10 +127,13 @@ int WLog_WriteImage(wLog* log, wLogMessage* message)
|
|||||||
|
|
||||||
EnterCriticalSection(&appender->lock);
|
EnterCriticalSection(&appender->lock);
|
||||||
|
|
||||||
|
if (appender->recursive)
|
||||||
|
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||||
|
|
||||||
|
appender->recursive = TRUE;
|
||||||
status = appender->WriteImageMessage(log, appender, message);
|
status = appender->WriteImageMessage(log, appender, message);
|
||||||
|
appender->recursive = FALSE;
|
||||||
LeaveCriticalSection(&appender->lock);
|
LeaveCriticalSection(&appender->lock);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +141,6 @@ int WLog_WritePacket(wLog* log, wLogMessage* message)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
wLogAppender* appender;
|
wLogAppender* appender;
|
||||||
|
|
||||||
appender = WLog_GetLogAppender(log);
|
appender = WLog_GetLogAppender(log);
|
||||||
|
|
||||||
if (!appender)
|
if (!appender)
|
||||||
@ -149,10 +154,13 @@ int WLog_WritePacket(wLog* log, wLogMessage* message)
|
|||||||
|
|
||||||
EnterCriticalSection(&appender->lock);
|
EnterCriticalSection(&appender->lock);
|
||||||
|
|
||||||
|
if (appender->recursive)
|
||||||
|
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||||
|
|
||||||
|
appender->recursive = TRUE;
|
||||||
status = appender->WritePacketMessage(log, appender, message);
|
status = appender->WritePacketMessage(log, appender, message);
|
||||||
|
appender->recursive = FALSE;
|
||||||
LeaveCriticalSection(&appender->lock);
|
LeaveCriticalSection(&appender->lock);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +179,6 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
|||||||
{
|
{
|
||||||
char formattedLogMessage[WLOG_MAX_STRING_SIZE];
|
char formattedLogMessage[WLOG_MAX_STRING_SIZE];
|
||||||
wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args);
|
wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args);
|
||||||
|
|
||||||
message->TextString = formattedLogMessage;
|
message->TextString = formattedLogMessage;
|
||||||
status = WLog_Write(log, message);
|
status = WLog_Write(log, message);
|
||||||
}
|
}
|
||||||
@ -180,7 +187,6 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
|||||||
{
|
{
|
||||||
message->Data = va_arg(args, void*);
|
message->Data = va_arg(args, void*);
|
||||||
message->Length = va_arg(args, int);
|
message->Length = va_arg(args, int);
|
||||||
|
|
||||||
status = WLog_WriteData(log, message);
|
status = WLog_WriteData(log, message);
|
||||||
}
|
}
|
||||||
else if (message->Type == WLOG_MESSAGE_IMAGE)
|
else if (message->Type == WLOG_MESSAGE_IMAGE)
|
||||||
@ -189,7 +195,6 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
|||||||
message->ImageWidth = va_arg(args, int);
|
message->ImageWidth = va_arg(args, int);
|
||||||
message->ImageHeight = va_arg(args, int);
|
message->ImageHeight = va_arg(args, int);
|
||||||
message->ImageBpp = va_arg(args, int);
|
message->ImageBpp = va_arg(args, int);
|
||||||
|
|
||||||
status = WLog_WriteImage(log, message);
|
status = WLog_WriteImage(log, message);
|
||||||
}
|
}
|
||||||
else if (message->Type == WLOG_MESSAGE_PACKET)
|
else if (message->Type == WLOG_MESSAGE_PACKET)
|
||||||
@ -197,7 +202,6 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
|||||||
message->PacketData = va_arg(args, void*);
|
message->PacketData = va_arg(args, void*);
|
||||||
message->PacketLength = va_arg(args, int);
|
message->PacketLength = va_arg(args, int);
|
||||||
message->PacketFlags = va_arg(args, int);
|
message->PacketFlags = va_arg(args, int);
|
||||||
|
|
||||||
status = WLog_WritePacket(log, message);
|
status = WLog_WritePacket(log, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,11 +212,8 @@ void WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
|
|
||||||
status = WLog_PrintMessageVA(log, message, args);
|
status = WLog_PrintMessageVA(log, message, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +271,6 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
|||||||
int count;
|
int count;
|
||||||
LPSTR names;
|
LPSTR names;
|
||||||
int iLevel;
|
int iLevel;
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
p = (char*) name;
|
p = (char*) name;
|
||||||
|
|
||||||
@ -284,11 +284,9 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
|||||||
filter->NameCount = count;
|
filter->NameCount = count;
|
||||||
filter->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
|
filter->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
|
||||||
filter->Names[count] = NULL;
|
filter->Names[count] = NULL;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
p = (char*) names;
|
p = (char*) names;
|
||||||
filter->Names[count++] = p;
|
filter->Names[count++] = p;
|
||||||
|
|
||||||
q = strrchr(p, ':');
|
q = strrchr(p, ':');
|
||||||
|
|
||||||
if (!q)
|
if (!q)
|
||||||
@ -296,7 +294,6 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
|||||||
|
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
q++;
|
q++;
|
||||||
|
|
||||||
iLevel = WLog_ParseLogLevel(q);
|
iLevel = WLog_ParseLogLevel(q);
|
||||||
|
|
||||||
if (iLevel < 0)
|
if (iLevel < 0)
|
||||||
@ -322,7 +319,6 @@ int WLog_ParseFilters()
|
|||||||
DWORD nSize;
|
DWORD nSize;
|
||||||
int status;
|
int status;
|
||||||
char** strs;
|
char** strs;
|
||||||
|
|
||||||
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
|
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
|
||||||
|
|
||||||
if (nSize < 1)
|
if (nSize < 1)
|
||||||
@ -334,7 +330,6 @@ int WLog_ParseFilters()
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
nSize = GetEnvironmentVariableA("WLOG_FILTER", env, nSize);
|
nSize = GetEnvironmentVariableA("WLOG_FILTER", env, nSize);
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
p = env;
|
p = env;
|
||||||
|
|
||||||
@ -345,11 +340,9 @@ int WLog_ParseFilters()
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_FilterCount = count;
|
g_FilterCount = count;
|
||||||
|
|
||||||
p = env;
|
p = env;
|
||||||
count = 0;
|
count = 0;
|
||||||
strs = (char**) calloc(g_FilterCount, sizeof(char*));
|
strs = (char**) calloc(g_FilterCount, sizeof(char*));
|
||||||
|
|
||||||
strs[count++] = p;
|
strs[count++] = p;
|
||||||
|
|
||||||
while ((p = strchr(p, ',')) != NULL)
|
while ((p = strchr(p, ',')) != NULL)
|
||||||
@ -373,7 +366,6 @@ int WLog_ParseFilters()
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(strs);
|
free(strs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +415,6 @@ int WLog_ParseName(wLog* log, LPCSTR name)
|
|||||||
char* p;
|
char* p;
|
||||||
int count;
|
int count;
|
||||||
LPSTR names;
|
LPSTR names;
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
p = (char*) name;
|
p = (char*) name;
|
||||||
|
|
||||||
@ -437,7 +428,6 @@ int WLog_ParseName(wLog* log, LPCSTR name)
|
|||||||
log->NameCount = count;
|
log->NameCount = count;
|
||||||
log->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
|
log->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
|
||||||
log->Names[count] = NULL;
|
log->Names[count] = NULL;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
p = (char*) names;
|
p = (char*) names;
|
||||||
log->Names[count++] = p;
|
log->Names[count++] = p;
|
||||||
@ -458,7 +448,6 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
|||||||
char* env;
|
char* env;
|
||||||
DWORD nSize;
|
DWORD nSize;
|
||||||
int iLevel;
|
int iLevel;
|
||||||
|
|
||||||
log = (wLog*) calloc(1, sizeof(wLog));
|
log = (wLog*) calloc(1, sizeof(wLog));
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
@ -469,10 +458,8 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
WLog_ParseName(log, name);
|
WLog_ParseName(log, name);
|
||||||
|
|
||||||
log->Parent = rootLogger;
|
log->Parent = rootLogger;
|
||||||
log->ChildrenCount = 0;
|
log->ChildrenCount = 0;
|
||||||
|
|
||||||
log->ChildrenSize = 16;
|
log->ChildrenSize = 16;
|
||||||
log->Children = (wLog**) calloc(log->ChildrenSize, sizeof(wLog*));
|
log->Children = (wLog**) calloc(log->ChildrenSize, sizeof(wLog*));
|
||||||
|
|
||||||
@ -488,14 +475,12 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
log->Level = WLOG_WARN;
|
log->Level = WLOG_WARN;
|
||||||
|
|
||||||
nSize = GetEnvironmentVariableA("WLOG_LEVEL", NULL, 0);
|
nSize = GetEnvironmentVariableA("WLOG_LEVEL", NULL, 0);
|
||||||
|
|
||||||
if (nSize)
|
if (nSize)
|
||||||
{
|
{
|
||||||
env = (LPSTR) malloc(nSize);
|
env = (LPSTR) malloc(nSize);
|
||||||
nSize = GetEnvironmentVariableA("WLOG_LEVEL", env, nSize);
|
nSize = GetEnvironmentVariableA("WLOG_LEVEL", env, nSize);
|
||||||
|
|
||||||
iLevel = WLog_ParseLogLevel(env);
|
iLevel = WLog_ParseLogLevel(env);
|
||||||
|
|
||||||
if (iLevel >= 0)
|
if (iLevel >= 0)
|
||||||
@ -528,7 +513,6 @@ void WLog_Free(wLog* log)
|
|||||||
free(log->Names[0]);
|
free(log->Names[0]);
|
||||||
free(log->Names);
|
free(log->Names);
|
||||||
free(log->Children);
|
free(log->Children);
|
||||||
|
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,11 +529,8 @@ wLog* WLog_GetRoot()
|
|||||||
{
|
{
|
||||||
g_RootLog = WLog_New("", NULL);
|
g_RootLog = WLog_New("", NULL);
|
||||||
g_RootLog->IsRoot = TRUE;
|
g_RootLog->IsRoot = TRUE;
|
||||||
|
|
||||||
WLog_ParseFilters();
|
WLog_ParseFilters();
|
||||||
|
|
||||||
logAppenderType = WLOG_APPENDER_CONSOLE;
|
logAppenderType = WLOG_APPENDER_CONSOLE;
|
||||||
|
|
||||||
nSize = GetEnvironmentVariableA("WLOG_APPENDER", NULL, 0);
|
nSize = GetEnvironmentVariableA("WLOG_APPENDER", NULL, 0);
|
||||||
|
|
||||||
if (nSize)
|
if (nSize)
|
||||||
@ -586,7 +567,6 @@ int WLog_AddChild(wLog* parent, wLog* child)
|
|||||||
|
|
||||||
parent->Children[parent->ChildrenCount++] = child;
|
parent->Children[parent->ChildrenCount++] = child;
|
||||||
child->Parent = parent;
|
child->Parent = parent;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,7 +576,6 @@ wLog* WLog_FindChild(LPCSTR name)
|
|||||||
wLog* root;
|
wLog* root;
|
||||||
wLog* child = NULL;
|
wLog* child = NULL;
|
||||||
BOOL found = FALSE;
|
BOOL found = FALSE;
|
||||||
|
|
||||||
root = WLog_GetRoot();
|
root = WLog_GetRoot();
|
||||||
|
|
||||||
for (index = 0; index < root->ChildrenCount; index++)
|
for (index = 0; index < root->ChildrenCount; index++)
|
||||||
@ -617,9 +596,7 @@ wLog* WLog_Get(LPCSTR name)
|
|||||||
{
|
{
|
||||||
wLog* log;
|
wLog* log;
|
||||||
wLog* root;
|
wLog* root;
|
||||||
|
|
||||||
root = WLog_GetRoot();
|
root = WLog_GetRoot();
|
||||||
|
|
||||||
log = WLog_FindChild(name);
|
log = WLog_FindChild(name);
|
||||||
|
|
||||||
if (!log)
|
if (!log)
|
||||||
@ -639,7 +616,6 @@ void WLog_Init()
|
|||||||
void WLog_Uninit()
|
void WLog_Uninit()
|
||||||
{
|
{
|
||||||
wLog* root = WLog_GetRoot();
|
wLog* root = WLog_GetRoot();
|
||||||
|
|
||||||
DWORD index;
|
DWORD index;
|
||||||
wLog* child = NULL;
|
wLog* child = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user