summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/utils/test/TestWLog.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
commita9bcc81f821d7c66f623779fa5147e728eb3c388 (patch)
tree98676963bcdd537ae5908a067a8eb110b93486a6 /winpr/libwinpr/utils/test/TestWLog.c
parentInitial commit. (diff)
downloadfreerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.tar.xz
freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.zip
Adding upstream version 3.3.0+dfsg1.upstream/3.3.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'winpr/libwinpr/utils/test/TestWLog.c')
-rw-r--r--winpr/libwinpr/utils/test/TestWLog.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/winpr/libwinpr/utils/test/TestWLog.c b/winpr/libwinpr/utils/test/TestWLog.c
new file mode 100644
index 0000000..92f1114
--- /dev/null
+++ b/winpr/libwinpr/utils/test/TestWLog.c
@@ -0,0 +1,69 @@
+#include <winpr/crt.h>
+#include <winpr/tchar.h>
+#include <winpr/path.h>
+#include <winpr/file.h>
+#include <winpr/wlog.h>
+
+int TestWLog(int argc, char* argv[])
+{
+ wLog* root = NULL;
+ wLog* logA = NULL;
+ wLog* logB = NULL;
+ wLogLayout* layout = NULL;
+ wLogAppender* appender = NULL;
+ char* tmp_path = NULL;
+ char* wlog_file = NULL;
+ int result = 1;
+
+ WINPR_UNUSED(argc);
+ WINPR_UNUSED(argv);
+
+ if (!(tmp_path = GetKnownPath(KNOWN_PATH_TEMP)))
+ {
+ fprintf(stderr, "Failed to get temporary directory!\n");
+ goto out;
+ }
+
+ root = WLog_GetRoot();
+
+ WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY);
+
+ appender = WLog_GetLogAppender(root);
+ if (!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log"))
+ goto out;
+ if (!WLog_ConfigureAppender(appender, "outputfilepath", tmp_path))
+ goto out;
+
+ layout = WLog_GetLogLayout(root);
+ WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - ");
+
+ WLog_OpenAppender(root);
+
+ logA = WLog_Get("com.test.ChannelA");
+ logB = WLog_Get("com.test.ChannelB");
+
+ WLog_SetLogLevel(logA, WLOG_INFO);
+ WLog_SetLogLevel(logB, WLOG_ERROR);
+
+ WLog_Print(logA, WLOG_INFO, "this is a test");
+ WLog_Print(logA, WLOG_WARN, "this is a %dnd %s", 2, "test");
+ WLog_Print(logA, WLOG_ERROR, "this is an error");
+ WLog_Print(logA, WLOG_TRACE, "this is a trace output");
+
+ WLog_Print(logB, WLOG_INFO, "just some info");
+ WLog_Print(logB, WLOG_WARN, "we're warning a %dnd %s", 2, "time");
+ WLog_Print(logB, WLOG_ERROR, "we've got an error");
+ WLog_Print(logB, WLOG_TRACE, "leaving a trace behind");
+
+ WLog_CloseAppender(root);
+
+ if ((wlog_file = GetCombinedPath(tmp_path, "test_w.log")))
+ winpr_DeleteFile(wlog_file);
+
+ result = 0;
+out:
+ free(wlog_file);
+ free(tmp_path);
+
+ return result;
+}