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