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