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