1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_journal_add_match</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
visibility: hidden;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
visibility: visible;
}
</style><a href="index.html">Index </a>·
<a href="systemd.directives.html">Directives </a>·
<a href="../python-systemd/index.html">Python </a>·
<span style="float:right">systemd 221</span><hr><div class="refentry"><a name="sd_journal_add_match"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_journal_add_match, sd_journal_add_disjunction, sd_journal_add_conjunction, sd_journal_flush_matches — Add or remove entry matches</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-journal.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_add_match</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>const void *<var class="pdparam">data</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_add_disjunction</b>(</code></td><td>sd_journal *<var class="pdparam">j</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_add_conjunction</b>(</code></td><td>sd_journal *<var class="pdparam">j</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">sd_journal_flush_matches</b>(</code></td><td>sd_journal *<var class="pdparam">j</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm47197589715440"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_journal_add_match()</code> 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
<a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
and
<a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>.
Matches are of the form "<code class="literal">FIELD=value</code>", 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
<a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>.
Whenever a new match is added the current entry position is reset,
and
<a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
(or a similar call) needs to be called before entries can be read
again.</p><p><code class="function">sd_journal_add_disjunction()</code> 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
<code class="function">sd_journal_add_disjunction()</code> or
<code class="function">sd_journal_add_conjunction()</code> are combined in
an OR with all matches added afterwards, until
<code class="function">sd_journal_add_disjunction()</code> or
<code class="function">sd_journal_add_conjunction()</code> is invoked again
to begin the next OR or AND term. </p><p><code class="function">sd_journal_add_conjunction()</code> 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
<code class="function">sd_journal_add_conjunction()</code> are combined in
an AND with all matches added afterwards, until
<code class="function">sd_journal_add_conjunction()</code> is invoked again
to begin the next AND term. The combination of
<code class="function">sd_journal_add_match()</code>,
<code class="function">sd_journal_add_disjunction()</code> and
<code class="function">sd_journal_add_conjunction()</code> may be used to
build complex search terms, even though full logical expressions
are not available. Note that
<code class="function">sd_journal_add_conjunction()</code> operates one
level 'higher' than
<code class="function">sd_journal_add_disjunction()</code>. 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).</p><p><code class="function">sd_journal_flush_matches()</code> 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.</p><p>Note that filtering via matches only applies to the way the
journal is read, it has no effect on storage on disk.</p></div><div class="refsect1"><a name="idm47197585081120"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value">¶</a></h2><p><code class="function">sd_journal_add_match()</code>,
<code class="function">sd_journal_add_disjunction()</code> and
<code class="function">sd_journal_add_conjunction()</code>
return 0 on success or a negative errno-style error
code. <code class="function">sd_journal_flush_matches()</code>
returns nothing.</p></div><div class="refsect1"><a name="idm47197585077600"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p>The <code class="function">sd_journal_add_match()</code>,
<code class="function">sd_journal_add_disjunction()</code>,
<code class="function">sd_journal_add_conjunction()</code> and
<code class="function">sd_journal_flush_matches()</code>
interfaces are available as a shared library, which can
be compiled and linked to with the
<code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
file.</p></div><div class="refsect1"><a name="idm47197585072432"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples">¶</a></h2><p>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):</p><pre class="programlisting">...
int add_matches(sd_journal *j) {
sd_journal_add_match(j, "_SYSTEMD_UNIT=avahi-daemon.service", 0);
sd_journal_add_match(j, "PRIORITY=0", 0);
sd_journal_add_match(j, "PRIORITY=1", 0);
sd_journal_add_match(j, "PRIORITY=2", 0);
sd_journal_add_match(j, "PRIORITY=3", 0);
sd_journal_add_disjunction(j);
sd_journal_add_match(j, "MESSAGE_ID=03bb1dab98ab4ecfbf6fff2738bdd964", 0);
}</pre></div><div class="refsect1"><a name="idm47197585069520"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
<a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
<a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>,
<a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>,
<a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>,
<a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
</p></div></div></body></html>
|