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