]>
Commit | Line | Data |
---|---|---|
f4e761c4 LP |
1 | <?xml version='1.0'?> <!--*-nxml-*--> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
f4e761c4 LP |
4 | |
5 | <!-- | |
572eb058 | 6 | SPDX-License-Identifier: LGPL-2.1+ |
f4e761c4 LP |
7 | --> |
8 | ||
7d6b2723 | 9 | <refentry id="sd_journal_add_match" xmlns:xi="http://www.w3.org/2001/XInclude"> |
f4e761c4 | 10 | |
798d3a52 ZJS |
11 | <refentryinfo> |
12 | <title>sd_journal_add_match</title> | |
13 | <productname>systemd</productname> | |
14 | ||
15 | <authorgroup> | |
16 | <author> | |
17 | <contrib>Developer</contrib> | |
18 | <firstname>Lennart</firstname> | |
19 | <surname>Poettering</surname> | |
20 | <email>lennart@poettering.net</email> | |
21 | </author> | |
22 | </authorgroup> | |
23 | </refentryinfo> | |
24 | ||
25 | <refmeta> | |
26 | <refentrytitle>sd_journal_add_match</refentrytitle> | |
27 | <manvolnum>3</manvolnum> | |
28 | </refmeta> | |
29 | ||
30 | <refnamediv> | |
31 | <refname>sd_journal_add_match</refname> | |
32 | <refname>sd_journal_add_disjunction</refname> | |
33 | <refname>sd_journal_add_conjunction</refname> | |
34 | <refname>sd_journal_flush_matches</refname> | |
35 | <refpurpose>Add or remove entry matches</refpurpose> | |
36 | </refnamediv> | |
37 | ||
38 | <refsynopsisdiv> | |
39 | <funcsynopsis> | |
40 | <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> | |
41 | ||
42 | <funcprototype> | |
43 | <funcdef>int <function>sd_journal_add_match</function></funcdef> | |
44 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
45 | <paramdef>const void *<parameter>data</parameter></paramdef> | |
46 | <paramdef>size_t <parameter>size</parameter></paramdef> | |
47 | </funcprototype> | |
48 | ||
49 | <funcprototype> | |
50 | <funcdef>int <function>sd_journal_add_disjunction</function></funcdef> | |
51 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
52 | </funcprototype> | |
53 | ||
54 | <funcprototype> | |
55 | <funcdef>int <function>sd_journal_add_conjunction</function></funcdef> | |
56 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
57 | </funcprototype> | |
58 | ||
59 | <funcprototype> | |
60 | <funcdef>void <function>sd_journal_flush_matches</function></funcdef> | |
61 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
62 | </funcprototype> | |
63 | </funcsynopsis> | |
64 | </refsynopsisdiv> | |
65 | ||
66 | <refsect1> | |
67 | <title>Description</title> | |
68 | ||
69 | <para><function>sd_journal_add_match()</function> adds a match by | |
70 | which to filter the entries of the journal file. Matches applied | |
71 | with this call will filter what can be iterated through and read | |
72 | from the journal file via calls like | |
73 | <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
74 | and | |
75 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
fb0c7174 ZJS |
76 | Parameter <parameter>data</parameter> must be of the form |
77 | <literal><replaceable>FIELD</replaceable>=<replaceable>value</replaceable></literal>, | |
78 | where the <replaceable>FIELD</replaceable> part is a short uppercase string consisting only | |
79 | of 0–9, A–Z and the underscore; it may not begin with two underscores or be the empty | |
80 | string. The <replaceable>value</replaceable> part may be anything, including binary. Parameter | |
81 | <parameter>size</parameter> specifies the number of bytes in <parameter>data</parameter> | |
82 | (i.e. the length of <replaceable>FIELD</replaceable>, plus one, plus the length of | |
83 | <replaceable>value</replaceable>). Parameter <parameter>size</parameter> may also be | |
84 | specified as <constant>0</constant>, in which case <parameter>data</parameter> | |
85 | must be a <constant>NUL</constant>-terminated string, and the bytes before the terminating | |
86 | zero are used as the match.</para> | |
87 | ||
88 | <para>If a match is applied, only entries with this field set | |
798d3a52 ZJS |
89 | will be iterated. Multiple matches may be active at the same time: |
90 | If they apply to different fields, only entries with both fields | |
91 | set like this will be iterated. If they apply to the same fields, | |
92 | only entries where the field takes one of the specified values | |
93 | will be iterated. Well known fields are documented in | |
94 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>. | |
95 | Whenever a new match is added the current entry position is reset, | |
96 | and | |
97 | <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
98 | (or a similar call) needs to be called before entries can be read | |
99 | again.</para> | |
100 | ||
101 | <para><function>sd_journal_add_disjunction()</function> may be | |
102 | used to insert a disjunction (i.e. logical OR) in the match list. | |
103 | If this call is invoked, all previously added matches since the | |
104 | last invocation of | |
105 | <function>sd_journal_add_disjunction()</function> or | |
106 | <function>sd_journal_add_conjunction()</function> are combined in | |
107 | an OR with all matches added afterwards, until | |
108 | <function>sd_journal_add_disjunction()</function> or | |
109 | <function>sd_journal_add_conjunction()</function> is invoked again | |
110 | to begin the next OR or AND term. </para> | |
111 | ||
112 | <para><function>sd_journal_add_conjunction()</function> may be | |
113 | used to insert a conjunction (i.e. logical AND) in the match list. | |
114 | If this call is invoked, all previously added matches since the | |
115 | last invocation of | |
116 | <function>sd_journal_add_conjunction()</function> are combined in | |
117 | an AND with all matches added afterwards, until | |
118 | <function>sd_journal_add_conjunction()</function> is invoked again | |
119 | to begin the next AND term. The combination of | |
120 | <function>sd_journal_add_match()</function>, | |
121 | <function>sd_journal_add_disjunction()</function> and | |
122 | <function>sd_journal_add_conjunction()</function> may be used to | |
123 | build complex search terms, even though full logical expressions | |
124 | are not available. Note that | |
125 | <function>sd_journal_add_conjunction()</function> operates one | |
126 | level 'higher' than | |
127 | <function>sd_journal_add_disjunction()</function>. It is hence | |
128 | possible to build an expression of AND terms, consisting of OR | |
129 | terms, consisting of AND terms, consisting of OR terms of matches | |
130 | (the latter OR expression is implicitly created for matches with | |
131 | the same field name, see above).</para> | |
132 | ||
133 | <para><function>sd_journal_flush_matches()</function> may be used | |
134 | to flush all matches, disjunction and conjunction terms again. | |
135 | After this call all filtering is removed and all entries in the | |
136 | journal will be iterated again.</para> | |
137 | ||
138 | <para>Note that filtering via matches only applies to the way the | |
139 | journal is read, it has no effect on storage on disk.</para> | |
140 | </refsect1> | |
141 | ||
142 | <refsect1> | |
143 | <title>Return Value</title> | |
144 | ||
145 | <para><function>sd_journal_add_match()</function>, | |
146 | <function>sd_journal_add_disjunction()</function> and | |
147 | <function>sd_journal_add_conjunction()</function> | |
148 | return 0 on success or a negative errno-style error | |
149 | code. <function>sd_journal_flush_matches()</function> | |
150 | returns nothing.</para> | |
151 | </refsect1> | |
152 | ||
7d6b2723 | 153 | <xi:include href="libsystemd-pkgconfig.xml" /> |
798d3a52 ZJS |
154 | |
155 | <refsect1> | |
156 | <title>Examples</title> | |
157 | ||
158 | <para>The following example adds matches to a journal context | |
159 | object to iterate only through messages generated by the Avahi | |
160 | service at the four error log levels, plus all messages of the | |
161 | message ID 03bb1dab98ab4ecfbf6fff2738bdd964 coming from any | |
162 | service (this example lacks the necessary error checking):</para> | |
163 | ||
1eecafb8 | 164 | <programlisting>… |
f4e761c4 | 165 | int add_matches(sd_journal *j) { |
798d3a52 ZJS |
166 | sd_journal_add_match(j, "_SYSTEMD_UNIT=avahi-daemon.service", 0); |
167 | sd_journal_add_match(j, "PRIORITY=0", 0); | |
168 | sd_journal_add_match(j, "PRIORITY=1", 0); | |
169 | sd_journal_add_match(j, "PRIORITY=2", 0); | |
170 | sd_journal_add_match(j, "PRIORITY=3", 0); | |
171 | sd_journal_add_disjunction(j); | |
172 | sd_journal_add_match(j, "MESSAGE_ID=03bb1dab98ab4ecfbf6fff2738bdd964", 0); | |
f4e761c4 | 173 | }</programlisting> |
798d3a52 | 174 | </refsect1> |
f4e761c4 | 175 | |
798d3a52 ZJS |
176 | <refsect1> |
177 | <title>See Also</title> | |
f4e761c4 | 178 | |
798d3a52 ZJS |
179 | <para> |
180 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
181 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
182 | <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
183 | <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
184 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
185 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry> | |
186 | </para> | |
187 | </refsect1> | |
f4e761c4 LP |
188 | |
189 | </refentry> |