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