]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-log.c
Merge pull request #7530 from poettering/uid-gid-fixes
[thirdparty/systemd.git] / src / test / test-log.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
877d54e9
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2012 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
21#include <stddef.h>
22#include <unistd.h>
23
f97b34a6 24#include "format-util.h"
877d54e9 25#include "log.h"
de0671ee 26#include "util.h"
877d54e9 27
ff524019
ZJS
28assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
29 == LOG_REALM_SYSTEMD);
30assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_LOCAL7 | LOG_DEBUG))
31 == LOG_REALM_UDEV);
32assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_LOCAL3 | LOG_DEBUG) & LOG_FACMASK)
33 == LOG_LOCAL3);
34assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_USER | LOG_INFO) & LOG_PRIMASK)
35 == LOG_INFO);
36
877d54e9
LP
37int main(int argc, char* argv[]) {
38
39 log_set_target(LOG_TARGET_CONSOLE);
40 log_open();
41
42 log_struct(LOG_INFO,
df0ff127 43 "MESSAGE=Waldo PID="PID_FMT, getpid_cached(),
877d54e9
LP
44 "SERVICE=piepapo",
45 NULL);
46
47 log_set_target(LOG_TARGET_JOURNAL);
48 log_open();
49
50 log_struct(LOG_INFO,
df0ff127 51 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
877d54e9
LP
52 "SERVICE=foobar",
53 NULL);
54
963ddb91 55 log_struct(LOG_INFO,
df0ff127 56 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
963ddb91
LP
57 "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",
58 (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,
59 "SUFFIX=GOT IT",
60 NULL);
61
877d54e9
LP
62 return 0;
63}