FreeRDP
Loading...
Searching...
No Matches
TestWLog.c
1#include <winpr/crt.h>
2#include <winpr/tchar.h>
3#include <winpr/path.h>
4#include <winpr/file.h>
5#include <winpr/wlog.h>
6
7int TestWLog(int argc, char* argv[])
8{
9 wLog* root = nullptr;
10 wLog* logA = nullptr;
11 wLog* logB = nullptr;
12 wLogLayout* layout = nullptr;
13 wLogAppender* appender = nullptr;
14 char* tmp_path = nullptr;
15 char* wlog_file = nullptr;
16 int result = 1;
17
18 WINPR_UNUSED(argc);
19 WINPR_UNUSED(argv);
20
21 if (!(tmp_path = GetKnownPath(KNOWN_PATH_TEMP)))
22 {
23 (void)fprintf(stderr, "Failed to get temporary directory!\n");
24 goto out;
25 }
26
27 root = WLog_GetRoot();
28 WINPR_ASSERT(root);
29
30 if (!WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY))
31 goto out;
32
33 appender = WLog_GetLogAppender(root);
34 if (!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log"))
35 goto out;
36 if (!WLog_ConfigureAppender(appender, "outputfilepath", tmp_path))
37 goto out;
38
39 layout = WLog_GetLogLayout(root);
40 if (!WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - "))
41 goto out;
42
43 if (!WLog_OpenAppender(root))
44 goto out;
45
46 logA = WLog_Get("com.test.ChannelA");
47 WINPR_ASSERT(logA);
48
49 logB = WLog_Get("com.test.ChannelB");
50 WINPR_ASSERT(logB);
51
52 if (!WLog_SetLogLevel(logA, WLOG_INFO))
53 goto out;
54 if (!WLog_SetLogLevel(logB, WLOG_ERROR))
55 goto out;
56
57 WLog_Print(logA, WLOG_INFO, "this is a test");
58 WLog_Print(logA, WLOG_WARN, "this is a %dnd %s", 2, "test");
59 WLog_Print(logA, WLOG_ERROR, "this is an error");
60 WLog_Print(logA, WLOG_TRACE, "this is a trace output");
61
62 WLog_Print(logB, WLOG_INFO, "just some info");
63 WLog_Print(logB, WLOG_WARN, "we're warning a %dnd %s", 2, "time");
64 WLog_Print(logB, WLOG_ERROR, "we've got an error");
65 WLog_Print(logB, WLOG_TRACE, "leaving a trace behind");
66
67 if (!WLog_CloseAppender(root))
68 goto out;
69
70 if ((wlog_file = GetCombinedPath(tmp_path, "test_w.log")))
71 winpr_DeleteFile(wlog_file);
72
73 result = 0;
74out:
75 free(wlog_file);
76 free(tmp_path);
77
78 return result;
79}