Debian Codegraph @

upstream/debian-unstable/man3/sd_journal_add_match.3

raw
1 '\" t
2 .TH "SD_JOURNAL_ADD_MATCH" "3" "" "systemd 261~rc3" "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)\&. Parameter
46 \fIdata\fR
47 must be of the form
48 "\fIFIELD\fR=\fIvalue\fR", where the
49 \fIFIELD\fR
50 part is a short uppercase string consisting only of 0\(en9, A\(enZ and the underscore; it may not begin with two underscores or be the empty string\&. The
51 \fIvalue\fR
52 part may be anything, including binary\&. Parameter
53 \fIsize\fR
54 specifies the number of bytes in
55 \fIdata\fR
56 (i\&.e\&. the length of
57 \fIFIELD\fR, plus one, plus the length of
58 \fIvalue\fR)\&. Parameter
59 \fIsize\fR
60 may also be specified as
61 \fB0\fR, in which case
62 \fIdata\fR
63 must be a
64 \fBNUL\fR\-terminated string, and the bytes before the terminating zero are used as the match\&.
65 .PP
66 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
67 \fBsystemd.journal-fields\fR(7)\&. Whenever a new match is added the current entry position is reset, and
68 \fBsd_journal_next\fR(3)
69 (or a similar call) needs to be called before entries can be read again\&.
70 .PP
71 \fBsd_journal_add_disjunction()\fR
72 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
73 \fBsd_journal_add_disjunction()\fR
74 or
75 \fBsd_journal_add_conjunction()\fR
76 are combined in an OR with all matches added afterwards, until
77 \fBsd_journal_add_disjunction()\fR
78 or
79 \fBsd_journal_add_conjunction()\fR
80 is invoked again to begin the next OR or AND term\&.
81 .PP
82 \fBsd_journal_add_conjunction()\fR
83 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
84 \fBsd_journal_add_conjunction()\fR
85 are combined in an AND with all matches added afterwards, until
86 \fBsd_journal_add_conjunction()\fR
87 is invoked again to begin the next AND term\&. The combination of
88 \fBsd_journal_add_match()\fR,
89 \fBsd_journal_add_disjunction()\fR
90 and
91 \fBsd_journal_add_conjunction()\fR
92 may be used to build complex search terms, even though full logical expressions are not available\&. Note that
93 \fBsd_journal_add_conjunction()\fR
94 operates one level \*(Aqhigher\*(Aq than
95 \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)\&.
96 .PP
97 \fBsd_journal_flush_matches()\fR
98 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\&.
99 .PP
100 Note that filtering via matches only applies to the way the journal is read, it has no effect on storage on disk\&.
101 .SH "RETURN VALUE"
102 .PP
103 \fBsd_journal_add_match()\fR,
104 \fBsd_journal_add_disjunction()\fR
105 and
106 \fBsd_journal_add_conjunction()\fR
107 return 0 on success or a negative errno\-style error code\&.
108 \fBsd_journal_flush_matches()\fR
109 returns nothing\&.
110 .SH "NOTES"
111 .PP
112 Functions described here are available as a shared library, which can be compiled against and linked to with the
113 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
114 file\&.
115 .PP
116 The code described here uses
117 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
118 \fBsetenv\fR(3)
119 from a parallel thread\&. It is recommended to only do calls to
120 \fBsetenv()\fR
121 from an early phase of the program when no other threads have been started\&.
122 .SH "EXAMPLES"
123 .PP
124 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):
125 .sp
126 .if n \{\
127 .RS 4
128 .\}
129 .nf
130 \&...
131 int add_matches(sd_journal *j) {
132 sd_journal_add_match(j, "_SYSTEMD_UNIT=avahi\-daemon\&.service", 0);
133 sd_journal_add_match(j, "PRIORITY=0", 0);
134 sd_journal_add_match(j, "PRIORITY=1", 0);
135 sd_journal_add_match(j, "PRIORITY=2", 0);
136 sd_journal_add_match(j, "PRIORITY=3", 0);
137 sd_journal_add_disjunction(j);
138 sd_journal_add_match(j, "MESSAGE_ID=03bb1dab98ab4ecfbf6fff2738bdd964", 0);
139 }
140 .fi
141 .if n \{\
142 .RE
143 .\}
144 .SH "HISTORY"
145 .PP
146 \fBsd_journal_add_match()\fR,
147 \fBsd_journal_add_disjunction()\fR, and
148 \fBsd_journal_flush_matches()\fR
149 were added in version 187\&.
150 .PP
151 \fBsd_journal_add_conjunction()\fR
152 was added in version 202\&.
153 .SH "SEE ALSO"
154 .PP
155 \fBsystemd\fR(1), \fBsd-journal\fR(3), \fBsd_journal_open\fR(3), \fBsd_journal_next\fR(3), \fBsd_journal_get_data\fR(3), \fBsystemd.journal-fields\fR(7)