]> git.proxmox.com Git - systemd.git/blob - man/sd_journal_add_match.3
Imported Upstream version 218
[systemd.git] / man / sd_journal_add_match.3
1 '\" t
2 .TH "SD_JOURNAL_ADD_MATCH" "3" "" "systemd 218" "sd_journal_add_match"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_journal_add_match, sd_journal_add_disjunction, sd_journal_add_conjunction, sd_journal_flush_matches \- Add or remove entry matches
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-journal\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_journal_add_match('u
32 .BI "int sd_journal_add_match(sd_journal\ *" "j" ", const\ void\ *" "data" ", size_t\ " "size" ");"
33 .HP \w'int\ sd_journal_add_disjunction('u
34 .BI "int sd_journal_add_disjunction(sd_journal\ *" "j" ");"
35 .HP \w'int\ sd_journal_add_conjunction('u
36 .BI "int sd_journal_add_conjunction(sd_journal\ *" "j" ");"
37 .HP \w'void\ sd_journal_flush_matches('u
38 .BI "void sd_journal_flush_matches(sd_journal\ *" "j" ");"
39 .SH "DESCRIPTION"
40 .PP
41 \fBsd_journal_add_match()\fR
42 adds a match by which to filter the entries of the journal file\&. Matches applied with this call will filter what can be iterated through and read from the journal file via calls like
43 \fBsd_journal_next\fR(3)
44 and
45 \fBsd_journal_get_data\fR(3)\&. Matches are of the form
46 "FIELD=value", where the field part is a short uppercase string consisting only of 0\-9, A\-Z and the underscore\&. It may not begin with two underscores or be the empty string\&. The value part may be any value, including binary\&. If a match is applied, only entries with this field set will be iterated\&. Multiple matches may be active at the same time: If they apply to different fields, only entries with both fields set like this will be iterated\&. If they apply to the same fields, only entries where the field takes one of the specified values will be iterated\&. Well known fields are documented in
47 \fBsystemd.journal-fields\fR(7)\&. Whenever a new match is added the current entry position is reset, and
48 \fBsd_journal_next\fR(3)
49 (or a similar call) needs to be called before entries can be read again\&.
50 .PP
51 \fBsd_journal_add_disjunction()\fR
52 may be used to insert a disjunction (i\&.e\&. logical OR) in the match list\&. If this call is invoked, all previously added matches since the last invocation of
53 \fBsd_journal_add_disjunction()\fR
54 or
55 \fBsd_journal_add_conjunction()\fR
56 are combined in an OR with all matches added afterwards, until
57 \fBsd_journal_add_disjunction()\fR
58 or
59 \fBsd_journal_add_conjunction()\fR
60 is invoked again to begin the next OR or AND term\&.
61 .PP
62 \fBsd_journal_add_conjunction()\fR
63 may be used to insert a conjunction (i\&.e\&. logical AND) in the match list\&. If this call is invoked, all previously added matches since the last invocation of
64 \fBsd_journal_add_conjunction()\fR
65 are combined in an AND with all matches added afterwards, until
66 \fBsd_journal_add_conjunction()\fR
67 is invoked again to begin the next AND term\&. The combination of
68 \fBsd_journal_add_match()\fR,
69 \fBsd_journal_add_disjunction()\fR
70 and
71 \fBsd_journal_add_conjunction()\fR
72 may be used to build complex search terms, even though full logical expressions are not available\&. Note that
73 \fBsd_journal_add_conjunction()\fR
74 operates one level \*(Aqhigher\*(Aq than
75 \fBsd_journal_add_disjunction()\fR\&. It is hence possible to build an expression of AND terms, consisting of OR terms, consisting of AND terms, consisting of OR terms of matches (the latter OR expression is implicitly created for matches with the same field name, see above)\&.
76 .PP
77 \fBsd_journal_flush_matches()\fR
78 may be used to flush all matches, disjunction and conjunction terms again\&. After this call all filtering is removed and all entries in the journal will be iterated again\&.
79 .PP
80 Note that filtering via matches only applies to the way the journal is read, it has no effect on storage on disk\&.
81 .SH "RETURN VALUE"
82 .PP
83 \fBsd_journal_add_match()\fR,
84 \fBsd_journal_add_disjunction()\fR
85 and
86 \fBsd_journal_add_conjunction()\fR
87 return 0 on success or a negative errno\-style error code\&.
88 \fBsd_journal_flush_matches()\fR
89 returns nothing\&.
90 .SH "NOTES"
91 .PP
92 The
93 \fBsd_journal_add_match()\fR,
94 \fBsd_journal_add_disjunction()\fR,
95 \fBsd_journal_add_conjunction()\fR
96 and
97 \fBsd_journal_flush_matches()\fR
98 interfaces are available as a shared library, which can be compiled and linked to with the
99 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
100 file\&.
101 .SH "EXAMPLES"
102 .PP
103 The following example adds matches to a journal context object to iterate only through messages generated by the Avahi service at the four error log levels, plus all messages of the message ID 03bb1dab98ab4ecfbf6fff2738bdd964 coming from any service (this example lacks the necessary error checking):
104 .sp
105 .if n \{\
106 .RS 4
107 .\}
108 .nf
109 \&.\&.\&.
110 int add_matches(sd_journal *j) {
111 sd_journal_add_match(j, "_SYSTEMD_UNIT=avahi\-daemon\&.service", 0);
112 sd_journal_add_match(j, "PRIORITY=0", 0);
113 sd_journal_add_match(j, "PRIORITY=1", 0);
114 sd_journal_add_match(j, "PRIORITY=2", 0);
115 sd_journal_add_match(j, "PRIORITY=3", 0);
116 sd_journal_add_disjunction(j);
117 sd_journal_add_match(j, "MESSAGE_ID=03bb1dab98ab4ecfbf6fff2738bdd964", 0);
118 }
119 .fi
120 .if n \{\
121 .RE
122 .\}
123 .SH "SEE ALSO"
124 .PP
125 \fBsystemd\fR(1),
126 \fBsd-journal\fR(3),
127 \fBsd_journal_open\fR(3),
128 \fBsd_journal_next\fR(3),
129 \fBsd_journal_get_data\fR(3),
130 \fBsystemd.journal-fields\fR(7)