chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / test / test-log.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   Copyright 2012 Lennart Poettering
4 ***/
5
6 #include <stddef.h>
7 #include <unistd.h>
8
9 #include "format-util.h"
10 #include "log.h"
11 /// Additional includes needed by elogind
12 #include "process-util.h"
13 //#include "util.h"
14
15 assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
16           == LOG_REALM_SYSTEMD);
17 assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_LOCAL7 | LOG_DEBUG))
18           == LOG_REALM_UDEV);
19 assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_LOCAL3 | LOG_DEBUG) & LOG_FACMASK)
20           == LOG_LOCAL3);
21 assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_USER | LOG_INFO) & LOG_PRIMASK)
22           == LOG_INFO);
23
24 #define X10(x) x x x x x x x x x x
25 #define X100(x) X10(X10(x))
26 #define X1000(x) X100(X10(x))
27
28 static void test_log_console(void) {
29         log_struct(LOG_INFO,
30                    "MESSAGE=Waldo PID="PID_FMT, getpid_cached(),
31                    "SERVICE=piepapo");
32 }
33
34 static void test_log_journal(void) {
35         log_struct(LOG_INFO,
36                    "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
37                    "SERVICE=foobar");
38
39         log_struct(LOG_INFO,
40                    "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
41                    "FORMAT_STR_TEST=1=%i A=%c 2=%hi 3=%li 4=%lli 1=%p foo=%s 2.5=%g 3.5=%g 4.5=%Lg",
42                    (int) 1, 'A', (short) 2, (long int) 3, (long long int) 4, (void*) 1, "foo", (float) 2.5f, (double) 3.5, (long double) 4.5,
43                    "SUFFIX=GOT IT");
44 }
45
46 static void test_long_lines(void) {
47         log_object_internal(LOG_NOTICE,
48                             EUCLEAN,
49                             X1000("abcd_") ".txt",
50                             1000000,
51                             X1000("fff") "unc",
52                             "OBJECT=",
53                             X1000("obj_") "ect",
54                             "EXTRA=",
55                             X1000("ext_") "tra",
56                             "asdfasdf %s asdfasdfa", "foobar");
57 }
58
59 int main(int argc, char* argv[]) {
60         int target;
61
62         for (target = 0; target <  _LOG_TARGET_MAX; target++) {
63                 log_set_target(target);
64                 log_open();
65
66                 test_log_console();
67                 test_log_journal();
68                 test_long_lines();
69         }
70
71         return 0;
72 }