]>
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 ZJS |
6 | SPDX-License-Identifier: LGPL-2.1+ |
7 | ||
f4e761c4 LP |
8 | This file is part of systemd. |
9 | ||
10 | Copyright 2012 Lennart Poettering | |
11 | ||
12 | systemd is free software; you can redistribute it and/or modify it | |
13 | under the terms of the GNU Lesser General Public License as published by | |
14 | the Free Software Foundation; either version 2.1 of the License, or | |
15 | (at your option) any later version. | |
16 | ||
17 | systemd is distributed in the hope that it will be useful, but | |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | Lesser General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU Lesser General Public License | |
23 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
24 | --> | |
25 | ||
26 | <refentry id="sd_journal_add_match"> | |
27 | ||
798d3a52 ZJS |
28 | <refentryinfo> |
29 | <title>sd_journal_add_match</title> | |
30 | <productname>systemd</productname> | |
31 | ||
32 | <authorgroup> | |
33 | <author> | |
34 | <contrib>Developer</contrib> | |
35 | <firstname>Lennart</firstname> | |
36 | <surname>Poettering</surname> | |
37 | <email>lennart@poettering.net</email> | |
38 | </author> | |
39 | </authorgroup> | |
40 | </refentryinfo> | |
41 | ||
42 | <refmeta> | |
43 | <refentrytitle>sd_journal_add_match</refentrytitle> | |
44 | <manvolnum>3</manvolnum> | |
45 | </refmeta> | |
46 | ||
47 | <refnamediv> | |
48 | <refname>sd_journal_add_match</refname> | |
49 | <refname>sd_journal_add_disjunction</refname> | |
50 | <refname>sd_journal_add_conjunction</refname> | |
51 | <refname>sd_journal_flush_matches</refname> | |
52 | <refpurpose>Add or remove entry matches</refpurpose> | |
53 | </refnamediv> | |
54 | ||
55 | <refsynopsisdiv> | |
56 | <funcsynopsis> | |
57 | <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> | |
58 | ||
59 | <funcprototype> | |
60 | <funcdef>int <function>sd_journal_add_match</function></funcdef> | |
61 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
62 | <paramdef>const void *<parameter>data</parameter></paramdef> | |
63 | <paramdef>size_t <parameter>size</parameter></paramdef> | |
64 | </funcprototype> | |
65 | ||
66 | <funcprototype> | |
67 | <funcdef>int <function>sd_journal_add_disjunction</function></funcdef> | |
68 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
69 | </funcprototype> | |
70 | ||
71 | <funcprototype> | |
72 | <funcdef>int <function>sd_journal_add_conjunction</function></funcdef> | |
73 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
74 | </funcprototype> | |
75 | ||
76 | <funcprototype> | |
77 | <funcdef>void <function>sd_journal_flush_matches</function></funcdef> | |
78 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
79 | </funcprototype> | |
80 | </funcsynopsis> | |
81 | </refsynopsisdiv> | |
82 | ||
83 | <refsect1> | |
84 | <title>Description</title> | |
85 | ||
86 | <para><function>sd_journal_add_match()</function> adds a match by | |
87 | which to filter the entries of the journal file. Matches applied | |
88 | with this call will filter what can be iterated through and read | |
89 | from the journal file via calls like | |
90 | <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
91 | and | |
92 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
fb0c7174 ZJS |
93 | Parameter <parameter>data</parameter> must be of the form |
94 | <literal><replaceable>FIELD</replaceable>=<replaceable>value</replaceable></literal>, | |
95 | where the <replaceable>FIELD</replaceable> part is a short uppercase string consisting only | |
96 | of 0–9, A–Z and the underscore; it may not begin with two underscores or be the empty | |
97 | string. The <replaceable>value</replaceable> part may be anything, including binary. Parameter | |
98 | <parameter>size</parameter> specifies the number of bytes in <parameter>data</parameter> | |
99 | (i.e. the length of <replaceable>FIELD</replaceable>, plus one, plus the length of | |
100 | <replaceable>value</replaceable>). Parameter <parameter>size</parameter> may also be | |
101 | specified as <constant>0</constant>, in which case <parameter>data</parameter> | |
102 | must be a <constant>NUL</constant>-terminated string, and the bytes before the terminating | |
103 | zero are used as the match.</para> | |
104 | ||
105 | <para>If a match is applied, only entries with this field set | |
798d3a52 ZJS |
106 | will be iterated. Multiple matches may be active at the same time: |
107 | If they apply to different fields, only entries with both fields | |
108 | set like this will be iterated. If they apply to the same fields, | |
109 | only entries where the field takes one of the specified values | |
110 | will be iterated. Well known fields are documented in | |
111 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>. | |
112 | Whenever a new match is added the current entry position is reset, | |
113 | and | |
114 | <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
115 | (or a similar call) needs to be called before entries can be read | |
116 | again.</para> | |
117 | ||
118 | <para><function>sd_journal_add_disjunction()</function> may be | |
119 | used to insert a disjunction (i.e. logical OR) in the match list. | |
120 | If this call is invoked, all previously added matches since the | |
121 | last invocation of | |
122 | <function>sd_journal_add_disjunction()</function> or | |
123 | <function>sd_journal_add_conjunction()</function> are combined in | |
124 | an OR with all matches added afterwards, until | |
125 | <function>sd_journal_add_disjunction()</function> or | |
126 | <function>sd_journal_add_conjunction()</function> is invoked again | |
127 | to begin the next OR or AND term. </para> | |
128 | ||
129 | <para><function>sd_journal_add_conjunction()</function> may be | |
130 | used to insert a conjunction (i.e. logical AND) in the match list. | |
131 | If this call is invoked, all previously added matches since the | |
132 | last invocation of | |
133 | <function>sd_journal_add_conjunction()</function> are combined in | |
134 | an AND with all matches added afterwards, until | |
135 | <function>sd_journal_add_conjunction()</function> is invoked again | |
136 | to begin the next AND term. The combination of | |
137 | <function>sd_journal_add_match()</function>, | |
138 | <function>sd_journal_add_disjunction()</function> and | |
139 | <function>sd_journal_add_conjunction()</function> may be used to | |
140 | build complex search terms, even though full logical expressions | |
141 | are not available. Note that | |
142 | <function>sd_journal_add_conjunction()</function> operates one | |
143 | level 'higher' than | |
144 | <function>sd_journal_add_disjunction()</function>. It is hence | |
145 | possible to build an expression of AND terms, consisting of OR | |
146 | terms, consisting of AND terms, consisting of OR terms of matches | |
147 | (the latter OR expression is implicitly created for matches with | |
148 | the same field name, see above).</para> | |
149 | ||
150 | <para><function>sd_journal_flush_matches()</function> may be used | |
151 | to flush all matches, disjunction and conjunction terms again. | |
152 | After this call all filtering is removed and all entries in the | |
153 | journal will be iterated again.</para> | |
154 | ||
155 | <para>Note that filtering via matches only applies to the way the | |
156 | journal is read, it has no effect on storage on disk.</para> | |
157 | </refsect1> | |
158 | ||
159 | <refsect1> | |
160 | <title>Return Value</title> | |
161 | ||
162 | <para><function>sd_journal_add_match()</function>, | |
163 | <function>sd_journal_add_disjunction()</function> and | |
164 | <function>sd_journal_add_conjunction()</function> | |
165 | return 0 on success or a negative errno-style error | |
166 | code. <function>sd_journal_flush_matches()</function> | |
167 | returns nothing.</para> | |
168 | </refsect1> | |
169 | ||
170 | <refsect1> | |
171 | <title>Notes</title> | |
172 | ||
a8d46a16 ZJS |
173 | <para>All functions listed here are thread-agnostic and only a single thread may operate |
174 | on a given <structname>sd_journal</structname> object.</para> | |
175 | ||
798d3a52 ZJS |
176 | <para>The <function>sd_journal_add_match()</function>, |
177 | <function>sd_journal_add_disjunction()</function>, | |
178 | <function>sd_journal_add_conjunction()</function> and | |
179 | <function>sd_journal_flush_matches()</function> | |
180 | interfaces are available as a shared library, which can | |
181 | be compiled and linked to with the | |
182 | <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
183 | file.</para> | |
184 | </refsect1> | |
185 | ||
186 | <refsect1> | |
187 | <title>Examples</title> | |
188 | ||
189 | <para>The following example adds matches to a journal context | |
190 | object to iterate only through messages generated by the Avahi | |
191 | service at the four error log levels, plus all messages of the | |
192 | message ID 03bb1dab98ab4ecfbf6fff2738bdd964 coming from any | |
193 | service (this example lacks the necessary error checking):</para> | |
194 | ||
1eecafb8 | 195 | <programlisting>… |
f4e761c4 | 196 | int add_matches(sd_journal *j) { |
798d3a52 ZJS |
197 | sd_journal_add_match(j, "_SYSTEMD_UNIT=avahi-daemon.service", 0); |
198 | sd_journal_add_match(j, "PRIORITY=0", 0); | |
199 | sd_journal_add_match(j, "PRIORITY=1", 0); | |
200 | sd_journal_add_match(j, "PRIORITY=2", 0); | |
201 | sd_journal_add_match(j, "PRIORITY=3", 0); | |
202 | sd_journal_add_disjunction(j); | |
203 | sd_journal_add_match(j, "MESSAGE_ID=03bb1dab98ab4ecfbf6fff2738bdd964", 0); | |
f4e761c4 LP |
204 | }</programlisting> |
205 | ||
798d3a52 | 206 | </refsect1> |
f4e761c4 | 207 | |
798d3a52 ZJS |
208 | <refsect1> |
209 | <title>See Also</title> | |
f4e761c4 | 210 | |
798d3a52 ZJS |
211 | <para> |
212 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
213 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
214 | <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
215 | <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
216 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
217 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry> | |
218 | </para> | |
219 | </refsect1> | |
f4e761c4 LP |
220 | |
221 | </refentry> |