]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_print.xml
journald: bring order of MaxLevelXYZ= setting explanations in sync with listed names
[thirdparty/systemd.git] / man / sd_journal_print.xml
CommitLineData
a8eedf49 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
eea10b26 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
db9ecf05 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
a8eedf49 5
7d6b2723 6<refentry id="sd_journal_print" xmlns:xi="http://www.w3.org/2001/XInclude">
a8eedf49 7
798d3a52
ZJS
8 <refentryinfo>
9 <title>sd_journal_print</title>
10 <productname>systemd</productname>
798d3a52
ZJS
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_journal_print</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_journal_print</refname>
20 <refname>sd_journal_printv</refname>
21 <refname>sd_journal_send</refname>
22 <refname>sd_journal_sendv</refname>
23 <refname>sd_journal_perror</refname>
24 <refname>SD_JOURNAL_SUPPRESS_LOCATION</refname>
c11edfee
ZJS
25 <refname>sd_journal_print_with_location</refname>
26 <refname>sd_journal_printv_with_location</refname>
27 <refname>sd_journal_send_with_location</refname>
28 <refname>sd_journal_sendv_with_location</refname>
29 <refname>sd_journal_perror_with_location</refname>
30
798d3a52
ZJS
31 <refpurpose>Submit log entries to the journal</refpurpose>
32 </refnamediv>
33
34 <refsynopsisdiv>
35 <funcsynopsis>
36 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
37
38 <funcprototype>
39 <funcdef>int <function>sd_journal_print</function></funcdef>
40 <paramdef>int <parameter>priority</parameter></paramdef>
41 <paramdef>const char *<parameter>format</parameter></paramdef>
1eecafb8 42 <paramdef>…</paramdef>
798d3a52
ZJS
43 </funcprototype>
44
45 <funcprototype>
46 <funcdef>int <function>sd_journal_printv</function></funcdef>
47 <paramdef>int <parameter>priority</parameter></paramdef>
48 <paramdef>const char *<parameter>format</parameter></paramdef>
49 <paramdef>va_list <parameter>ap</parameter></paramdef>
50 </funcprototype>
51
52 <funcprototype>
53 <funcdef>int <function>sd_journal_send</function></funcdef>
54 <paramdef>const char *<parameter>format</parameter></paramdef>
1eecafb8 55 <paramdef>…</paramdef>
798d3a52
ZJS
56 </funcprototype>
57
58 <funcprototype>
59 <funcdef>int <function>sd_journal_sendv</function></funcdef>
60 <paramdef>const struct iovec *<parameter>iov</parameter></paramdef>
61 <paramdef>int <parameter>n</parameter></paramdef>
62 </funcprototype>
63
64 <funcprototype>
65 <funcdef>int <function>sd_journal_perror</function></funcdef>
66 <paramdef>const char *<parameter>message</parameter></paramdef>
67 </funcprototype>
68
c11edfee
ZJS
69 <funcprototype>
70 <funcdef>int <function>sd_journal_print_with_location</function></funcdef>
37035235 71 <paramdef>int <parameter>priority</parameter></paramdef>
c11edfee
ZJS
72 <paramdef>const char *<parameter>file</parameter></paramdef>
73 <paramdef>const char *<parameter>line</parameter></paramdef>
74 <paramdef>const char *<parameter>func</parameter></paramdef>
c11edfee
ZJS
75 <paramdef>const char *<parameter>format</parameter></paramdef>
76 <paramdef>…</paramdef>
77 </funcprototype>
78
79 <funcprototype>
80 <funcdef>int <function>sd_journal_printv_with_location</function></funcdef>
81 <paramdef>int <parameter>priority</parameter></paramdef>
82 <paramdef>const char *<parameter>file</parameter></paramdef>
83 <paramdef>const char *<parameter>line</parameter></paramdef>
84 <paramdef>const char *<parameter>func</parameter></paramdef>
85 <paramdef>const char *<parameter>format</parameter></paramdef>
86 <paramdef>va_list <parameter>ap</parameter></paramdef>
87 </funcprototype>
88
89 <funcprototype>
90 <funcdef>int <function>sd_journal_send_with_location</function></funcdef>
91 <paramdef>const char *<parameter>file</parameter></paramdef>
92 <paramdef>const char *<parameter>line</parameter></paramdef>
93 <paramdef>const char *<parameter>func</parameter></paramdef>
94 <paramdef>const char *<parameter>format</parameter></paramdef>
95 <paramdef>…</paramdef>
96 </funcprototype>
97
98 <funcprototype>
99 <funcdef>int <function>sd_journal_sendv_with_location</function></funcdef>
100 <paramdef>const char *<parameter>file</parameter></paramdef>
101 <paramdef>const char *<parameter>line</parameter></paramdef>
102 <paramdef>const char *<parameter>func</parameter></paramdef>
103 <paramdef>const struct iovec *<parameter>iov</parameter></paramdef>
104 <paramdef>int <parameter>n</parameter></paramdef>
105 </funcprototype>
106
107 <funcprototype>
108 <funcdef>int <function>sd_journal_perror_with_location</function></funcdef>
109 <paramdef>const char *<parameter>file</parameter></paramdef>
110 <paramdef>const char *<parameter>line</parameter></paramdef>
111 <paramdef>const char *<parameter>func</parameter></paramdef>
112 <paramdef>const char *<parameter>message</parameter></paramdef>
113 </funcprototype>
798d3a52
ZJS
114 </funcsynopsis>
115 </refsynopsisdiv>
116
117 <refsect1>
118 <title>Description</title>
119
4c5db93f
LP
120 <para><function>sd_journal_print()</function> may be used to submit simple, plain text log entries to the system
121 journal. The first argument is a priority value. This is followed by a format string and its parameters, similar to
122 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
798d3a52 123 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
11fcfc53 124 Note that currently the resulting message will be truncated to <constant>LINE_MAX - 8</constant>.
4c5db93f
LP
125 The priority value is one of <constant>LOG_EMERG</constant>, <constant>LOG_ALERT</constant>,
126 <constant>LOG_CRIT</constant>, <constant>LOG_ERR</constant>, <constant>LOG_WARNING</constant>,
127 <constant>LOG_NOTICE</constant>, <constant>LOG_INFO</constant>, <constant>LOG_DEBUG</constant>, as defined in
128 <filename>syslog.h</filename>, see <citerefentry
129 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry> for details. It is
130 recommended to use this call to submit log messages in the application locale or system locale and in UTF-8 format,
131 but no such restrictions are enforced. Note that log messages written using this function are generally not
132 expected to end in a new-line character. However, as all trailing whitespace (including spaces, new-lines,
133 tabulators and carriage returns) are automatically stripped from the logged string, it is acceptable to specify one
0d23bc57
LP
134 (or more). Empty lines (after trailing whitespace removal) are suppressed. On non-empty lines, leading whitespace
135 (as well as inner whitespace) is left unmodified. </para>
798d3a52
ZJS
136
137 <para><function>sd_journal_printv()</function> is similar to
138 <function>sd_journal_print()</function> but takes a variable
139 argument list encapsulated in an object of type
140 <varname>va_list</varname> (see
3ba3a79d 141 <citerefentry project='man-pages'><refentrytitle>stdarg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
142 for more information) instead of the format string. It is
143 otherwise equivalent in behavior.</para>
144
4c5db93f
LP
145 <para><function>sd_journal_send()</function> may be used to submit structured log entries to the system journal. It
146 takes a series of format strings, each immediately followed by their associated parameters, terminated by
147 <constant>NULL</constant>. The strings passed should be of the format <literal>VARIABLE=value</literal>. The
148 variable name must be in uppercase and consist only of characters, numbers and underscores, and may not begin with
149 an underscore. (All assignments that do not follow this syntax will be ignored.) The value can be of any size and
150 format. It is highly recommended to submit text strings formatted in the UTF-8 character encoding only, and submit
151 binary fields only when formatting in UTF-8 strings is not sensible. A number of well-known fields are defined, see
152 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
153 details, but additional application defined fields may be used. A variable may be assigned more than one value per
154 entry. If this function is used, trailing whitespace is automatically removed from each formatted field.</para>
155
156 <para><function>sd_journal_sendv()</function> is similar to <function>sd_journal_send()</function> but takes an
157 array of <varname>struct iovec</varname> (as defined in <filename>uio.h</filename>, see <citerefentry
158 project='man-pages'><refentrytitle>readv</refentrytitle><manvolnum>3</manvolnum></citerefentry> for details)
159 instead of the format string. Each structure should reference one field of the entry to submit. The second argument
160 specifies the number of structures in the array. <function>sd_journal_sendv()</function> is particularly useful to
301a21a8 161 submit binary objects to the journal where that is necessary. Note that this function will not strip trailing
4c5db93f
LP
162 whitespace of the passed fields, but passes the specified data along unmodified. This is different from both
163 <function>sd_journal_print()</function> and <function>sd_journal_send()</function> described above, which are based
164 on format strings, and do strip trailing whitespace.</para>
798d3a52
ZJS
165
166 <para><function>sd_journal_perror()</function> is a similar to
3ba3a79d 167 <citerefentry project='die-net'><refentrytitle>perror</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52 168 and writes a message to the journal that consists of the passed
b938cb90 169 string, suffixed with ": " and a human-readable representation of
798d3a52
ZJS
170 the current error code stored in
171 <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
172 If the message string is passed as <constant>NULL</constant> or
173 empty string, only the error string representation will be
174 written, prefixed with nothing. An additional journal field ERRNO=
175 is included in the entry containing the numeric error code
176 formatted as decimal string. The log priority used is
177 <constant>LOG_ERR</constant> (3).</para>
178
179 <para>Note that <function>sd_journal_send()</function> is a
180 wrapper around <function>sd_journal_sendv()</function> to make it
181 easier to use when only text strings shall be submitted. Also, the
182 following two calls are mostly equivalent:</para>
183
184 <programlisting>sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
a8eedf49
LP
185
186sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
4c5db93f
LP
187 "PRIORITY=%i", LOG_INFO,
188 NULL);</programlisting>
798d3a52 189
c11edfee
ZJS
190 <para>Note that these calls implicitly add fields for the source file, function name and code line where
191 invoked. This is implemented with macros. If this is not desired, it can be turned off by defining
192 <constant>SD_JOURNAL_SUPPRESS_LOCATION</constant> before including <filename>sd-journal.h</filename>.
193 </para>
194
725d9713
YW
195 <para><function>sd_journal_print_with_location()</function>,
196 <function>sd_journal_printv_with_location()</function>, <function>sd_journal_send_with_location()</function>,
197 <function>sd_journal_sendv_with_location()</function>, and
198 <function>sd_journal_perror_with_location()</function> are similar to their counterparts without
c11edfee 199 <literal>_with_location</literal>, but accept additional parameters to explicitly set the source file
673ed959
HL
200 name, function, and line. The arguments <literal>file</literal> and <literal>line</literal> must contain valid
201 journal entries including the variable name, e.g. <literal>CODE_FILE=src/foo.c</literal> and
202 <literal>CODE_LINE=666</literal>, while <literal>func</literal> must only contain the function name, i.e. the value
203 without <literal>CODE_FUNC=</literal>. These variants are primarily useful when writing custom wrappers, for
204 example in bindings for a different language.</para>
798d3a52
ZJS
205
206 <para><citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
207 and <function>sd_journal_print()</function> may
208 largely be used interchangeably
209 functionality-wise. However, note that log messages
210 logged via the former take a different path to the
211 journal server than the later, and hence global
212 chronological ordering between the two streams cannot
213 be guaranteed. Using
214 <function>sd_journal_print()</function> has the
215 benefit of logging source code line, filenames, and
216 functions as metadata along all entries, and
217 guaranteeing chronological ordering with structured
218 log entries that are generated via
219 <function>sd_journal_send()</function>. Using
220 <function>syslog()</function> has the benefit of being
221 more portable.</para>
8ee62e53
LP
222
223 <para>These functions implement a client to the <ulink
224 url="https://systemd.io/JOURNAL_NATIVE_PROTOCOL">Native Journal Protocol</ulink>.</para>
798d3a52
ZJS
225 </refsect1>
226
227 <refsect1>
228 <title>Return Value</title>
229
c11edfee
ZJS
230 <para>The ten functions return 0 on success or a negative errno-style error code. The
231 <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>
232 variable itself is not altered.</para>
798d3a52
ZJS
233
234 <para>If
235 <citerefentry><refentrytitle>systemd-journald</refentrytitle><manvolnum>8</manvolnum></citerefentry>
236 is not running (the socket is not present), those functions do
237 nothing, and also return 0.</para>
238 </refsect1>
239
240 <refsect1>
a8d46a16 241 <title>Thread safety</title>
64a7ef8b
LP
242
243 <xi:include href="threads-aware.xml" xpointer="safe"/>
a8d46a16 244
c11edfee
ZJS
245 <para><function>sd_journal_sendv()</function> and <function>sd_journal_sendv_with_location()</function>
246 are "async signal safe" in the meaning of
247 <citerefentry project='man-pages'><refentrytitle>signal-safety</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
798d3a52
ZJS
248 </para>
249
725d9713
YW
250 <para><function>sd_journal_print()</function>,
251 <function>sd_journal_printv()</function>,
252 <function>sd_journal_send()</function>,
253 <function>sd_journal_perror()</function>,
c11edfee
ZJS
254 and their counterparts with <literal>_with_location</literal>
255 are not async signal safe.</para>
798d3a52
ZJS
256 </refsect1>
257
7d6b2723 258 <xi:include href="libsystemd-pkgconfig.xml" />
798d3a52 259
69106f47
AK
260 <refsect1>
261 <title>History</title>
00f95506
AK
262 <para><function>sd_journal_print()</function>,
263 <function>sd_journal_printv()</function>,
264 <function>sd_journal_send()</function>, and
265 <function>sd_journal_sendv()</function> were added in version 187.</para>
69106f47 266 <para><function>sd_journal_perror()</function> was added in version 188.</para>
00f95506
AK
267 <para><function>sd_journal_print_with_location()</function>,
268 <function>sd_journal_printv_with_location()</function>,
269 <function>sd_journal_send_with_location()</function>,
270 <function>sd_journal_sendv_with_location()</function>, and
271 <function>sd_journal_perror_with_location()</function> were added in version 246.</para>
69106f47
AK
272 </refsect1>
273
798d3a52
ZJS
274 <refsect1>
275 <title>See Also</title>
276
13a69c12
DT
277 <para><simplelist type="inline">
278 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
279 <member><citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
280 <member><citerefentry><refentrytitle>sd_journal_stream_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
281 <member><citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
282 <member><citerefentry project='die-net'><refentrytitle>perror</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
283 <member><citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
284 <member><citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
285 <member><citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
286 <member><citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
287 </simplelist></para>
798d3a52 288 </refsect1>
a8eedf49
LP
289
290</refentry>