2 #include <winpr/tchar.h>
3 #include <winpr/path.h>
4 #include <winpr/wlog.h>
13 static const char*
function = NULL;
14 static const char* channels[] = {
"com.test.channelA",
"com.test.channelB" };
16 static const test_t messages[] = { { WLOG_INFO,
"this is a test",
"com.test.channelA" },
17 { WLOG_INFO,
"Just some info",
"com.test.channelB" },
18 { WLOG_WARN,
"this is a %dnd %s",
"com.test.channelA" },
19 { WLOG_WARN,
"we're warning a %dnd %s",
"com.test.channelB" },
20 { WLOG_ERROR,
"this is an error",
"com.test.channelA" },
21 { WLOG_ERROR,
"we've got an error",
"com.test.channelB" },
22 { WLOG_TRACE,
"this is a trace output",
"com.test.channelA" },
23 { WLOG_TRACE,
"leaving a trace behind",
"com.test.channelB" } };
25 static BOOL success = TRUE;
33 else if (strcmp(msg->FileName, __FILE__) != 0)
35 else if (strcmp(msg->FunctionName,
function) != 0)
37 else if (strcmp(msg->PrefixString, messages[pos].channel) != 0)
39 else if (msg->Level != messages[pos].level)
41 else if (strcmp(msg->FormatString, messages[pos].msg) != 0)
47 (void)fprintf(stderr,
"Test failed!\n");
53 static BOOL CallbackAppenderMessage(
const wLogMessage* msg)
59 static BOOL CallbackAppenderData(
const wLogMessage* msg)
61 (void)fprintf(stdout,
"%s\n", __func__);
65 static BOOL CallbackAppenderImage(
const wLogMessage* msg)
67 (void)fprintf(stdout,
"%s\n", __func__);
71 static BOOL CallbackAppenderPackage(
const wLogMessage* msg)
73 (void)fprintf(stdout,
"%s\n", __func__);
77 int TestWLogCallback(
int argc,
char* argv[])
82 wLogLayout* layout = NULL;
83 wLogAppender* appender = NULL;
91 root = WLog_GetRoot();
93 WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK);
95 appender = WLog_GetLogAppender(root);
97 callbacks.data = CallbackAppenderData;
98 callbacks.image = CallbackAppenderImage;
99 callbacks.message = CallbackAppenderMessage;
100 callbacks.package = CallbackAppenderPackage;
102 if (!WLog_ConfigureAppender(appender,
"callbacks", (
void*)&callbacks))
105 layout = WLog_GetLogLayout(root);
106 WLog_Layout_SetPrefixFormat(root, layout,
"%mn");
108 WLog_OpenAppender(root);
110 logA = WLog_Get(channels[0]);
111 logB = WLog_Get(channels[1]);
113 WLog_SetLogLevel(logA, WLOG_TRACE);
114 WLog_SetLogLevel(logB, WLOG_TRACE);
116 WLog_Print(logA, messages[0].level, messages[0].msg);
117 WLog_Print(logB, messages[1].level, messages[1].msg);
118 WLog_Print(logA, messages[2].level, messages[2].msg, 2,
"test");
119 WLog_Print(logB, messages[3].level, messages[3].msg, 2,
"time");
120 WLog_Print(logA, messages[4].level, messages[4].msg);
121 WLog_Print(logB, messages[5].level, messages[5].msg);
122 WLog_Print(logA, messages[6].level, messages[6].msg);
123 WLog_Print(logB, messages[7].level, messages[7].msg);
125 WLog_CloseAppender(root);
127 return success ? 0 : -1;