20 #include <winpr/config.h>
24 void WLog_Appender_Free(wLog* log, wLogAppender* appender)
31 WLog_Layout_Free(log, appender->Layout);
32 appender->Layout = NULL;
35 DeleteCriticalSection(&appender->lock);
36 appender->Free(appender);
39 wLogAppender* WLog_GetLogAppender(wLog* log)
45 return WLog_GetLogAppender(log->Parent);
50 BOOL WLog_OpenAppender(wLog* log)
53 wLogAppender* appender = NULL;
55 appender = WLog_GetLogAppender(log);
63 if (!appender->active)
65 status = appender->Open(log, appender);
66 appender->active = TRUE;
72 BOOL WLog_CloseAppender(wLog* log)
75 wLogAppender* appender = NULL;
77 appender = WLog_GetLogAppender(log);
87 status = appender->Close(log, appender);
88 appender->active = FALSE;
94 static wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
96 wLogAppender* appender = NULL;
101 switch (logAppenderType)
103 case WLOG_APPENDER_CONSOLE:
104 appender = WLog_ConsoleAppender_New(log);
106 case WLOG_APPENDER_FILE:
107 appender = WLog_FileAppender_New(log);
109 case WLOG_APPENDER_BINARY:
110 appender = WLog_BinaryAppender_New(log);
112 case WLOG_APPENDER_CALLBACK:
113 appender = WLog_CallbackAppender_New(log);
115 #ifdef WINPR_HAVE_SYSLOG_H
116 case WLOG_APPENDER_SYSLOG:
117 appender = WLog_SyslogAppender_New(log);
120 #ifdef WINPR_HAVE_JOURNALD_H
121 case WLOG_APPENDER_JOURNALD:
122 appender = WLog_JournaldAppender_New(log);
125 case WLOG_APPENDER_UDP:
126 appender = WLog_UdpAppender_New(log);
129 (void)fprintf(stderr,
"%s: unknown handler type %" PRIu32
"\n", __func__,
136 appender = WLog_ConsoleAppender_New(log);
141 if (!(appender->Layout = WLog_Layout_New(log)))
143 WLog_Appender_Free(log, appender);
147 InitializeCriticalSectionAndSpinCount(&appender->lock, 4000);
152 BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType)
159 WLog_Appender_Free(log, log->Appender);
160 log->Appender = NULL;
163 log->Appender = WLog_Appender_New(log, logAppenderType);
164 return log->Appender != NULL;
167 BOOL WLog_ConfigureAppender(wLogAppender* appender,
const char* setting,
void* value)
170 if (!appender || !setting || (strnlen(setting, 2) == 0))
174 return appender->Set(appender, setting, value);