Added recursion guard to logging functions.
This commit is contained in:
parent
763410a66d
commit
c32c48fbb6
@ -128,6 +128,7 @@ typedef int (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* ap
|
||||
DWORD State; \
|
||||
wLogLayout* Layout; \
|
||||
CRITICAL_SECTION lock; \
|
||||
BOOL recursive; \
|
||||
void* TextMessageContext; \
|
||||
void* DataMessageContext; \
|
||||
void* ImageMessageContext; \
|
||||
|
@ -60,7 +60,6 @@ int WLog_Write(wLog* log, wLogMessage* message)
|
||||
{
|
||||
int status;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
@ -74,10 +73,13 @@ int WLog_Write(wLog* log, wLogMessage* message)
|
||||
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||
|
||||
appender->recursive = TRUE;
|
||||
status = appender->WriteMessage(log, appender, message);
|
||||
|
||||
appender->recursive = FALSE;
|
||||
LeaveCriticalSection(&appender->lock);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -85,7 +87,6 @@ int WLog_WriteData(wLog* log, wLogMessage* message)
|
||||
{
|
||||
int status;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
@ -99,10 +100,13 @@ int WLog_WriteData(wLog* log, wLogMessage* message)
|
||||
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||
|
||||
appender->recursive = TRUE;
|
||||
status = appender->WriteDataMessage(log, appender, message);
|
||||
|
||||
appender->recursive = FALSE;
|
||||
LeaveCriticalSection(&appender->lock);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -110,7 +114,6 @@ int WLog_WriteImage(wLog* log, wLogMessage* message)
|
||||
{
|
||||
int status;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
@ -124,10 +127,13 @@ int WLog_WriteImage(wLog* log, wLogMessage* message)
|
||||
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||
|
||||
appender->recursive = TRUE;
|
||||
status = appender->WriteImageMessage(log, appender, message);
|
||||
|
||||
appender->recursive = FALSE;
|
||||
LeaveCriticalSection(&appender->lock);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -135,7 +141,6 @@ int WLog_WritePacket(wLog* log, wLogMessage* message)
|
||||
{
|
||||
int status;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
@ -149,10 +154,13 @@ int WLog_WritePacket(wLog* log, wLogMessage* message)
|
||||
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
fprintf(stderr, "%s: Recursion detected!!!!", __FUNCTION__);
|
||||
|
||||
appender->recursive = TRUE;
|
||||
status = appender->WritePacketMessage(log, appender, message);
|
||||
|
||||
appender->recursive = FALSE;
|
||||
LeaveCriticalSection(&appender->lock);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -171,7 +179,6 @@ int WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
||||
{
|
||||
char formattedLogMessage[WLOG_MAX_STRING_SIZE];
|
||||
wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args);
|
||||
|
||||
message->TextString = formattedLogMessage;
|
||||
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->Length = va_arg(args, int);
|
||||
|
||||
status = WLog_WriteData(log, message);
|
||||
}
|
||||
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->ImageHeight = va_arg(args, int);
|
||||
message->ImageBpp = va_arg(args, int);
|
||||
|
||||
status = WLog_WriteImage(log, message);
|
||||
}
|
||||
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->PacketLength = va_arg(args, int);
|
||||
message->PacketFlags = va_arg(args, int);
|
||||
|
||||
status = WLog_WritePacket(log, message);
|
||||
}
|
||||
|
||||
@ -208,11 +212,8 @@ void WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
|
||||
{
|
||||
int status;
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
|
||||
status = WLog_PrintMessageVA(log, message, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
@ -270,7 +271,6 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
||||
int count;
|
||||
LPSTR names;
|
||||
int iLevel;
|
||||
|
||||
count = 1;
|
||||
p = (char*) name;
|
||||
|
||||
@ -284,11 +284,9 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
||||
filter->NameCount = count;
|
||||
filter->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
|
||||
filter->Names[count] = NULL;
|
||||
|
||||
count = 0;
|
||||
p = (char*) names;
|
||||
filter->Names[count++] = p;
|
||||
|
||||
q = strrchr(p, ':');
|
||||
|
||||
if (!q)
|
||||
@ -296,7 +294,6 @@ int WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
||||
|
||||
*q = '\0';
|
||||
q++;
|
||||
|
||||
iLevel = WLog_ParseLogLevel(q);
|
||||
|
||||
if (iLevel < 0)
|
||||
@ -322,7 +319,6 @@ int WLog_ParseFilters()
|
||||
DWORD nSize;
|
||||
int status;
|
||||
char** strs;
|
||||
|
||||
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
|
||||
|
||||
if (nSize < 1)
|
||||
@ -334,7 +330,6 @@ int WLog_ParseFilters()
|
||||
return -1;
|
||||
|
||||
nSize = GetEnvironmentVariableA("WLOG_FILTER", env, nSize);
|
||||
|
||||
count = 1;
|
||||
p = env;
|
||||
|
||||
@ -345,11 +340,9 @@ int WLog_ParseFilters()
|
||||
}
|
||||
|
||||
g_FilterCount = count;
|
||||
|
||||
p = env;
|
||||
count = 0;
|
||||
strs = (char**) calloc(g_FilterCount, sizeof(char*));
|
||||
|
||||
strs[count++] = p;
|
||||
|
||||
while ((p = strchr(p, ',')) != NULL)
|
||||
@ -373,7 +366,6 @@ int WLog_ParseFilters()
|
||||
}
|
||||
|
||||
free(strs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -423,7 +415,6 @@ int WLog_ParseName(wLog* log, LPCSTR name)
|
||||
char* p;
|
||||
int count;
|
||||
LPSTR names;
|
||||
|
||||
count = 1;
|
||||
p = (char*) name;
|
||||
|
||||
@ -437,7 +428,6 @@ int WLog_ParseName(wLog* log, LPCSTR name)
|
||||
log->NameCount = count;
|
||||
log->Names = (LPSTR*) malloc(sizeof(LPSTR) * (count + 1));
|
||||
log->Names[count] = NULL;
|
||||
|
||||
count = 0;
|
||||
p = (char*) names;
|
||||
log->Names[count++] = p;
|
||||
@ -458,7 +448,6 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
char* env;
|
||||
DWORD nSize;
|
||||
int iLevel;
|
||||
|
||||
log = (wLog*) calloc(1, sizeof(wLog));
|
||||
|
||||
if (log)
|
||||
@ -469,10 +458,8 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
return NULL;
|
||||
|
||||
WLog_ParseName(log, name);
|
||||
|
||||
log->Parent = rootLogger;
|
||||
log->ChildrenCount = 0;
|
||||
|
||||
log->ChildrenSize = 16;
|
||||
log->Children = (wLog**) calloc(log->ChildrenSize, sizeof(wLog*));
|
||||
|
||||
@ -488,14 +475,12 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
else
|
||||
{
|
||||
log->Level = WLOG_WARN;
|
||||
|
||||
nSize = GetEnvironmentVariableA("WLOG_LEVEL", NULL, 0);
|
||||
|
||||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
nSize = GetEnvironmentVariableA("WLOG_LEVEL", env, nSize);
|
||||
|
||||
iLevel = WLog_ParseLogLevel(env);
|
||||
|
||||
if (iLevel >= 0)
|
||||
@ -528,7 +513,6 @@ void WLog_Free(wLog* log)
|
||||
free(log->Names[0]);
|
||||
free(log->Names);
|
||||
free(log->Children);
|
||||
|
||||
free(log);
|
||||
}
|
||||
}
|
||||
@ -545,11 +529,8 @@ wLog* WLog_GetRoot()
|
||||
{
|
||||
g_RootLog = WLog_New("", NULL);
|
||||
g_RootLog->IsRoot = TRUE;
|
||||
|
||||
WLog_ParseFilters();
|
||||
|
||||
logAppenderType = WLOG_APPENDER_CONSOLE;
|
||||
|
||||
nSize = GetEnvironmentVariableA("WLOG_APPENDER", NULL, 0);
|
||||
|
||||
if (nSize)
|
||||
@ -586,7 +567,6 @@ int WLog_AddChild(wLog* parent, wLog* child)
|
||||
|
||||
parent->Children[parent->ChildrenCount++] = child;
|
||||
child->Parent = parent;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -596,7 +576,6 @@ wLog* WLog_FindChild(LPCSTR name)
|
||||
wLog* root;
|
||||
wLog* child = NULL;
|
||||
BOOL found = FALSE;
|
||||
|
||||
root = WLog_GetRoot();
|
||||
|
||||
for (index = 0; index < root->ChildrenCount; index++)
|
||||
@ -617,9 +596,7 @@ wLog* WLog_Get(LPCSTR name)
|
||||
{
|
||||
wLog* log;
|
||||
wLog* root;
|
||||
|
||||
root = WLog_GetRoot();
|
||||
|
||||
log = WLog_FindChild(name);
|
||||
|
||||
if (!log)
|
||||
@ -639,7 +616,6 @@ void WLog_Init()
|
||||
void WLog_Uninit()
|
||||
{
|
||||
wLog* root = WLog_GetRoot();
|
||||
|
||||
DWORD index;
|
||||
wLog* child = NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user