chiark / gitweb /
71551f779a04843620e5bd307dffe5e360b39f17
[elogind.git] / man / sd_journal_print.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3         "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
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
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                 <refpurpose>Submit log entries to the journal</refpurpose>
51         </refnamediv>
52
53         <refsynopsisdiv>
54                 <funcsynopsis>
55                         <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
56
57                         <funcprototype>
58                                 <funcdef>int <function>sd_journal_print</function></funcdef>
59                                 <paramdef>int <parameter>priority</parameter></paramdef>
60                                 <paramdef>const char* <parameter>format</parameter></paramdef>
61                                 <paramdef>...</paramdef>
62                         </funcprototype>
63
64                         <funcprototype>
65                                 <funcdef>int <function>sd_journal_printv</function></funcdef>
66                                 <paramdef>int <parameter>priority</parameter></paramdef>
67                                 <paramdef>const char* <parameter>format</parameter></paramdef>
68                                 <paramdef>va_list <parameter>ap</parameter></paramdef>
69                         </funcprototype>
70
71                         <funcprototype>
72                                 <funcdef>int <function>sd_journal_send</function></funcdef>
73                                 <paramdef>const char* <parameter>format</parameter></paramdef>
74                                 <paramdef>...</paramdef>
75                         </funcprototype>
76
77                         <funcprototype>
78                                 <funcdef>int <function>sd_journal_sendv</function></funcdef>
79                                 <paramdef>const struct iovec *<parameter>iov</parameter></paramdef>
80                                 <paramdef>int <parameter>n</parameter></paramdef>
81                         </funcprototype>
82
83                 </funcsynopsis>
84         </refsynopsisdiv>
85
86         <refsect1>
87                 <title>Description</title>
88
89                 <para><function>sd_journal_print()</function> may be
90                 used to submit simple, plain text log entries to the
91                 system journal. The first argument is a priority
92                 value. This is followed by a format string and its
93                 parameters, similar to
94                 <citerefentry><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>
95                 or
96                 <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>. The
97                 priority value is one of
98                 <literal>LOG_EMERG</literal>,
99                 <literal>LOG_ALERT</literal>,
100                 <literal>LOG_CRIT</literal>,
101                 <literal>LOG_ERR</literal>,
102                 <literal>LOG_WARNING</literal>,
103                 <literal>LOG_NOTICE</literal>,
104                 <literal>LOG_INFO</literal>,
105                 <literal>LOG_DEBUG</literal>, as defined in
106                 <filename>syslog.h</filename>, see
107                 <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
108                 for details. It is recommended to use this call to
109                 submit log messages in the application locale or system
110                 locale and in UTF-8 format, but no such restrictions
111                 are enforced.</para>
112
113                 <para><function>sd_journal_printv()</function> is
114                 similar to <function>sd_journal_print()</function> but
115                 takes a variable argument list encapsulated in an
116                 object of type <literal>va_list</literal> (see
117                 <citerefentry><refentrytitle>stdarg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
118                 for more information) instead of the format string. It
119                 is otherwise equivalent in behaviour.</para>
120
121                 <para><function>sd_journal_send()</function> may be
122                 used to submit structured log entries to the system
123                 journal. It takes a series of format strings, each
124                 immediately followed by their associated parameters,
125                 terminated by a NULL. The strings passed should be of
126                 the format <literal>VARIABLE=value</literal>. The
127                 variable name must be in uppercase and consist only
128                 of characters, numbers and underscores, and may not
129                 begin with an underscore. The value can be of any size
130                 and format. It is highly recommended to submit
131                 text strings formatted in the UTF-8 character encoding
132                 only, and submit binary fields only when formatting in
133                 UTf-8 strings is not sensible. A number of well known
134                 fields are defined, see
135                 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
136                 for details, but additional application defined fields
137                 may be used.</para>
138
139                 <para><function>sd_journal_sendv()</function> is
140                 similar to <function>sd_journal_send()</function> but
141                 takes an array of <literal>struct iovec</literal> (as
142                 defined in <filename>uio.h</filename>, see
143                 <citerefentry><refentrytitle>readv</refentrytitle><manvolnum>3</manvolnum></citerefentry>
144                 for details) instead of the format string. Each
145                 structure should reference one field of the entry to
146                 submit. The second argument specifies the number of
147                 structures in the
148                 array. <function>sd_journal_sendv()</function> is
149                 particularly useful to submit binary objects to the
150                 journal where that is necessary.</para>
151
152                 <para>Note that <function>sd_journal_send()</function>
153                 is a wapper around
154                 <function>sd_journal_sendv()</function> to make it
155                 easier to use when only text strings shall be
156                 submitted. Also, the following two calls are
157                 mostly equivalent:</para>
158
159                 <programlisting>sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
160
161 sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
162                 "PRIORITY=%i", LOG_INFO,
163                 NULL);</programlisting>
164
165                 <para>Note that these calls implicitly add fields for
166                 the source file, function name and code line where
167                 invoked. This is implemented with macros. If this is
168                 not desired it can be turned off by defining
169                 SD_JOURNAL_SUPPRESS_LOCATION before including
170                 <filename>sd-journal.h</filename>.</para>
171
172                 <para><citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
173                 and and <function>sd_journal_print()</function> may
174                 mostly be used interchangably
175                 functionality-wise. However, note that log messages
176                 logged via the former take a different path to the
177                 journal server than the later, and hence global
178                 chronological ordering between the two streams cannot
179                 be guaranteed. Using
180                 <function>sd_journal_print()</function> has the
181                 benefit of logging source code line, file names, and
182                 functions as meta data along all entries, and
183                 guaranteeing chronological ordering with structured
184                 log entries that are generated via
185                 <function>sd_journal_send()</function>. Using
186                 <function>syslog()</function> has the benefit of being
187                 more portable.</para>
188         </refsect1>
189
190         <refsect1>
191                 <title>Return Value</title>
192
193                 <para>The four calls return 0 on success or a
194                 negative errno-style error code.</para>
195         </refsect1>
196
197         <refsect1>
198                 <title>Notes</title>
199
200                 <para>The <function>sd_journal_print()</function>,
201                 <function>sd_journal_printv()</function>,
202                 <function>sd_journal_send()</function> and
203                 <function>sd_journal_sendv()</function> interfaces
204                 are available as shared library, which can be compiled
205                 and linked to with the
206                 <literal>libsystemd-journal</literal>
207                 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
208                 file.</para>
209         </refsect1>
210
211         <refsect1>
212                 <title>See Also</title>
213
214                 <para>
215                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
216                         <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
217                         <citerefentry><refentrytitle>sd_journal_stream_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
218                         <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
219                         <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
220                 </para>
221         </refsect1>
222
223 </refentry>