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