]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_print.xml
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / sd_journal_print.xml
CommitLineData
a8eedf49
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">
a8eedf49
LP
4
5<!--
572eb058
ZJS
6 SPDX-License-Identifier: LGPL-2.1+
7
a8eedf49
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_print">
27
798d3a52
ZJS
28 <refentryinfo>
29 <title>sd_journal_print</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_print</refentrytitle>
44 <manvolnum>3</manvolnum>
45 </refmeta>
46
47 <refnamediv>
48 <refname>sd_journal_print</refname>
49 <refname>sd_journal_printv</refname>
50 <refname>sd_journal_send</refname>
51 <refname>sd_journal_sendv</refname>
52 <refname>sd_journal_perror</refname>
53 <refname>SD_JOURNAL_SUPPRESS_LOCATION</refname>
54 <refpurpose>Submit log entries to the journal</refpurpose>
55 </refnamediv>
56
57 <refsynopsisdiv>
58 <funcsynopsis>
59 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
60
61 <funcprototype>
62 <funcdef>int <function>sd_journal_print</function></funcdef>
63 <paramdef>int <parameter>priority</parameter></paramdef>
64 <paramdef>const char *<parameter>format</parameter></paramdef>
1eecafb8 65 <paramdef>…</paramdef>
798d3a52
ZJS
66 </funcprototype>
67
68 <funcprototype>
69 <funcdef>int <function>sd_journal_printv</function></funcdef>
70 <paramdef>int <parameter>priority</parameter></paramdef>
71 <paramdef>const char *<parameter>format</parameter></paramdef>
72 <paramdef>va_list <parameter>ap</parameter></paramdef>
73 </funcprototype>
74
75 <funcprototype>
76 <funcdef>int <function>sd_journal_send</function></funcdef>
77 <paramdef>const char *<parameter>format</parameter></paramdef>
1eecafb8 78 <paramdef>…</paramdef>
798d3a52
ZJS
79 </funcprototype>
80
81 <funcprototype>
82 <funcdef>int <function>sd_journal_sendv</function></funcdef>
83 <paramdef>const struct iovec *<parameter>iov</parameter></paramdef>
84 <paramdef>int <parameter>n</parameter></paramdef>
85 </funcprototype>
86
87 <funcprototype>
88 <funcdef>int <function>sd_journal_perror</function></funcdef>
89 <paramdef>const char *<parameter>message</parameter></paramdef>
90 </funcprototype>
91
92 </funcsynopsis>
93 </refsynopsisdiv>
94
95 <refsect1>
96 <title>Description</title>
97
4c5db93f
LP
98 <para><function>sd_journal_print()</function> may be used to submit simple, plain text log entries to the system
99 journal. The first argument is a priority value. This is followed by a format string and its parameters, similar to
100 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
798d3a52 101 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
4c5db93f
LP
102 The priority value is one of <constant>LOG_EMERG</constant>, <constant>LOG_ALERT</constant>,
103 <constant>LOG_CRIT</constant>, <constant>LOG_ERR</constant>, <constant>LOG_WARNING</constant>,
104 <constant>LOG_NOTICE</constant>, <constant>LOG_INFO</constant>, <constant>LOG_DEBUG</constant>, as defined in
105 <filename>syslog.h</filename>, see <citerefentry
106 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry> for details. It is
107 recommended to use this call to submit log messages in the application locale or system locale and in UTF-8 format,
108 but no such restrictions are enforced. Note that log messages written using this function are generally not
109 expected to end in a new-line character. However, as all trailing whitespace (including spaces, new-lines,
110 tabulators and carriage returns) are automatically stripped from the logged string, it is acceptable to specify one
0d23bc57
LP
111 (or more). Empty lines (after trailing whitespace removal) are suppressed. On non-empty lines, leading whitespace
112 (as well as inner whitespace) is left unmodified. </para>
798d3a52
ZJS
113
114 <para><function>sd_journal_printv()</function> is similar to
115 <function>sd_journal_print()</function> but takes a variable
116 argument list encapsulated in an object of type
117 <varname>va_list</varname> (see
3ba3a79d 118 <citerefentry project='man-pages'><refentrytitle>stdarg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
119 for more information) instead of the format string. It is
120 otherwise equivalent in behavior.</para>
121
4c5db93f
LP
122 <para><function>sd_journal_send()</function> may be used to submit structured log entries to the system journal. It
123 takes a series of format strings, each immediately followed by their associated parameters, terminated by
124 <constant>NULL</constant>. The strings passed should be of the format <literal>VARIABLE=value</literal>. The
125 variable name must be in uppercase and consist only of characters, numbers and underscores, and may not begin with
126 an underscore. (All assignments that do not follow this syntax will be ignored.) The value can be of any size and
127 format. It is highly recommended to submit text strings formatted in the UTF-8 character encoding only, and submit
128 binary fields only when formatting in UTF-8 strings is not sensible. A number of well-known fields are defined, see
129 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
130 details, but additional application defined fields may be used. A variable may be assigned more than one value per
131 entry. If this function is used, trailing whitespace is automatically removed from each formatted field.</para>
132
133 <para><function>sd_journal_sendv()</function> is similar to <function>sd_journal_send()</function> but takes an
134 array of <varname>struct iovec</varname> (as defined in <filename>uio.h</filename>, see <citerefentry
135 project='man-pages'><refentrytitle>readv</refentrytitle><manvolnum>3</manvolnum></citerefentry> for details)
136 instead of the format string. Each structure should reference one field of the entry to submit. The second argument
137 specifies the number of structures in the array. <function>sd_journal_sendv()</function> is particularly useful to
301a21a8 138 submit binary objects to the journal where that is necessary. Note that this function will not strip trailing
4c5db93f
LP
139 whitespace of the passed fields, but passes the specified data along unmodified. This is different from both
140 <function>sd_journal_print()</function> and <function>sd_journal_send()</function> described above, which are based
141 on format strings, and do strip trailing whitespace.</para>
798d3a52
ZJS
142
143 <para><function>sd_journal_perror()</function> is a similar to
3ba3a79d 144 <citerefentry project='die-net'><refentrytitle>perror</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52 145 and writes a message to the journal that consists of the passed
b938cb90 146 string, suffixed with ": " and a human-readable representation of
798d3a52
ZJS
147 the current error code stored in
148 <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
149 If the message string is passed as <constant>NULL</constant> or
150 empty string, only the error string representation will be
151 written, prefixed with nothing. An additional journal field ERRNO=
152 is included in the entry containing the numeric error code
153 formatted as decimal string. The log priority used is
154 <constant>LOG_ERR</constant> (3).</para>
155
156 <para>Note that <function>sd_journal_send()</function> is a
157 wrapper around <function>sd_journal_sendv()</function> to make it
158 easier to use when only text strings shall be submitted. Also, the
159 following two calls are mostly equivalent:</para>
160
161 <programlisting>sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
a8eedf49
LP
162
163sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
4c5db93f
LP
164 "PRIORITY=%i", LOG_INFO,
165 NULL);</programlisting>
798d3a52
ZJS
166
167 <para>Note that these calls implicitly add fields for the source
168 file, function name and code line where invoked. This is
169 implemented with macros. If this is not desired, it can be turned
170 off by defining SD_JOURNAL_SUPPRESS_LOCATION before including
171 <filename>sd-journal.h</filename>.</para>
172
173 <para><citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
174 and <function>sd_journal_print()</function> may
175 largely be used interchangeably
176 functionality-wise. However, note that log messages
177 logged via the former take a different path to the
178 journal server than the later, and hence global
179 chronological ordering between the two streams cannot
180 be guaranteed. Using
181 <function>sd_journal_print()</function> has the
182 benefit of logging source code line, filenames, and
183 functions as metadata along all entries, and
184 guaranteeing chronological ordering with structured
185 log entries that are generated via
186 <function>sd_journal_send()</function>. Using
187 <function>syslog()</function> has the benefit of being
188 more portable.</para>
189 </refsect1>
190
191 <refsect1>
192 <title>Return Value</title>
193
951aba62
LP
194 <para>The five calls return 0 on success or a negative errno-style error code. The <citerefentry
195 project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry> variable itself is
196 not altered.</para>
798d3a52
ZJS
197
198 <para>If
199 <citerefentry><refentrytitle>systemd-journald</refentrytitle><manvolnum>8</manvolnum></citerefentry>
200 is not running (the socket is not present), those functions do
201 nothing, and also return 0.</para>
202 </refsect1>
203
204 <refsect1>
a8d46a16
ZJS
205 <title>Thread safety</title>
206 <para>All functions listed here are thread-safe and may be called in parallel from multiple threads.</para>
207
2695b872
LP
208 <para><function>sd_journal_sendv()</function> is "async signal safe" in the meaning of <citerefentry
209 project='man-pages'><refentrytitle>signal-safety</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
798d3a52
ZJS
210 </para>
211
212 <para><function>sd_journal_print</function>,
213 <function>sd_journal_printv</function>,
214 <function>sd_journal_send</function>, and
215 <function>sd_journal_perror</function> are
216 not async signal safe.</para>
217 </refsect1>
218
219 <refsect1>
220 <title>Notes</title>
221
951aba62
LP
222 <para>The <function>sd_journal_print()</function>, <function>sd_journal_printv()</function>,
223 <function>sd_journal_send()</function>, <function>sd_journal_sendv()</function> and
224 <function>sd_journal_perror()</function> interfaces are available as a shared library, which can be compiled and
225 linked to with the <constant>libsystemd</constant> <citerefentry
226 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
798d3a52
ZJS
227 </refsect1>
228
229 <refsect1>
230 <title>See Also</title>
231
232 <para>
233 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
234 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
235 <citerefentry><refentrytitle>sd_journal_stream_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
236 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
3ba3a79d 237 <citerefentry project='die-net'><refentrytitle>perror</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
798d3a52
ZJS
238 <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
239 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
3ba3a79d
ZJS
240 <citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
241 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
798d3a52
ZJS
242 </para>
243 </refsect1>
a8eedf49
LP
244
245</refentry>