FreeRDP
Loading...
Searching...
No Matches
TestWLogTags.c
1#include <stdio.h>
2#include <string.h>
3
4#include <winpr/wlog.h>
5
6/* Every WLog_* call writes under its own tag, also when one file logs under several tags: the
7 * logger a call looks up must not be shared with the other calls of its file. */
8
9static const char* expected[] = { "com.test.tags.first", "com.test.tags.second",
10 "com.test.tags.second", "com.test.tags.first" };
11static size_t received = 0;
12static BOOL success = TRUE;
13
14static BOOL message(const wLogMessage* msg)
15{
16 if (!msg || (received >= ARRAYSIZE(expected)))
17 {
18 success = FALSE;
19 return TRUE;
20 }
21 if (strcmp(msg->PrefixString, expected[received]) != 0)
22 {
23 (void)fprintf(stderr, "message %" PRIuz " '%s' came under %s, expected %s\n", received,
24 msg->FormatString, msg->PrefixString, expected[received]);
25 success = FALSE;
26 }
27 received++;
28 return TRUE;
29}
30
31static BOOL ignore(WINPR_ATTR_UNUSED const wLogMessage* msg)
32{
33 return TRUE;
34}
35
36int TestWLogTags(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char* argv[])
37{
38 wLog* root = WLog_GetRoot();
39 if (!WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK))
40 return -1;
41
42 wLogAppender* appender = WLog_GetLogAppender(root);
43 if (!appender)
44 return -1;
45
46 wLogCallbacks callbacks = {
47 .data = ignore, .image = ignore, .message = message, .package = ignore
48 };
49 if (!WLog_ConfigureAppender(appender, "callbacks", (void*)&callbacks))
50 return -1;
51
52 wLogLayout* layout = WLog_GetLogLayout(root);
53 if (!WLog_Layout_SetPrefixFormat(root, layout, "%mn"))
54 return -1;
55 if (!WLog_OpenAppender(root))
56 return -1;
57
58 for (size_t x = 0; x < ARRAYSIZE(expected); x++)
59 {
60 if (!WLog_SetLogLevel(WLog_Get(expected[x]), WLOG_TRACE))
61 return -1;
62 }
63
64 WLog_INFO("com.test.tags.first", "first");
65 WLog_INFO("com.test.tags.second", "second");
66 WLog_ERR("com.test.tags.second", "an error");
67 WLog_DBG("com.test.tags.first", "first again");
68
69 if (!WLog_CloseAppender(root))
70 return -1;
71
72 if (received != ARRAYSIZE(expected))
73 {
74 (void)fprintf(stderr, "%" PRIuz " messages, expected %" PRIuz "\n", received,
75 ARRAYSIZE(expected));
76 return -1;
77 }
78 return success ? 0 : -1;
79}
Layout layout(float leftWidth, float leftHeight, float rightWidth, float rightHeight, float width, float margin)