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