]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-enum.c
3f00200adfc3cb7683054fd8a159cad244fa0742
[thirdparty/systemd.git] / src / journal / test-journal-enum.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2012 Lennart Poettering
4 ***/
5
6 #include <stdio.h>
7
8 #include "sd-journal.h"
9
10 #include "journal-internal.h"
11 #include "log.h"
12 #include "macro.h"
13
14 int main(int argc, char *argv[]) {
15 unsigned n = 0;
16 _cleanup_(sd_journal_closep) sd_journal*j = NULL;
17
18 log_set_max_level(LOG_DEBUG);
19
20 assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0);
21
22 assert_se(sd_journal_add_match(j, "_TRANSPORT=syslog", 0) >= 0);
23 assert_se(sd_journal_add_match(j, "_UID=0", 0) >= 0);
24
25 SD_JOURNAL_FOREACH_BACKWARDS(j) {
26 const void *d;
27 size_t l;
28
29 assert_se(sd_journal_get_data(j, "MESSAGE", &d, &l) >= 0);
30
31 printf("%.*s\n", (int) l, (char*) d);
32
33 n++;
34 if (n >= 10)
35 break;
36 }
37
38 return 0;
39 }