2012-07-09 21:46:21 +08:00
|
|
|
|
<?xml version='1.0'?> <!--*-nxml-*-->
|
|
|
|
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
|
|
|
|
|
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
|
|
Copyright 2012 Lennart Poettering
|
|
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<refentry id="sd_journal_print">
|
|
|
|
|
|
|
|
|
|
<refentryinfo>
|
|
|
|
|
<title>sd_journal_print</title>
|
|
|
|
|
<productname>systemd</productname>
|
|
|
|
|
|
|
|
|
|
<authorgroup>
|
|
|
|
|
<author>
|
|
|
|
|
<contrib>Developer</contrib>
|
|
|
|
|
<firstname>Lennart</firstname>
|
|
|
|
|
<surname>Poettering</surname>
|
|
|
|
|
<email>lennart@poettering.net</email>
|
|
|
|
|
</author>
|
|
|
|
|
</authorgroup>
|
|
|
|
|
</refentryinfo>
|
|
|
|
|
|
|
|
|
|
<refmeta>
|
|
|
|
|
<refentrytitle>sd_journal_print</refentrytitle>
|
|
|
|
|
<manvolnum>3</manvolnum>
|
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>sd_journal_print</refname>
|
|
|
|
|
<refname>sd_journal_printv</refname>
|
|
|
|
|
<refname>sd_journal_send</refname>
|
|
|
|
|
<refname>sd_journal_sendv</refname>
|
2012-07-31 22:09:01 +08:00
|
|
|
|
<refname>sd_journal_perror</refname>
|
2012-07-14 05:10:23 +08:00
|
|
|
|
<refname>SD_JOURNAL_SUPPRESS_LOCATION</refname>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<refpurpose>Submit log entries to the journal</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo>
|
|
|
|
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>sd_journal_print</function></funcdef>
|
|
|
|
|
<paramdef>int <parameter>priority</parameter></paramdef>
|
2014-05-08 07:28:46 +08:00
|
|
|
|
<paramdef>const char *<parameter>format</parameter></paramdef>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<paramdef>...</paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>sd_journal_printv</function></funcdef>
|
|
|
|
|
<paramdef>int <parameter>priority</parameter></paramdef>
|
2014-05-08 07:28:46 +08:00
|
|
|
|
<paramdef>const char *<parameter>format</parameter></paramdef>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<paramdef>va_list <parameter>ap</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>sd_journal_send</function></funcdef>
|
2014-05-08 07:28:46 +08:00
|
|
|
|
<paramdef>const char *<parameter>format</parameter></paramdef>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<paramdef>...</paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>sd_journal_sendv</function></funcdef>
|
|
|
|
|
<paramdef>const struct iovec *<parameter>iov</parameter></paramdef>
|
|
|
|
|
<paramdef>int <parameter>n</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
2012-07-31 22:09:01 +08:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>sd_journal_perror</function></funcdef>
|
2014-05-08 07:28:46 +08:00
|
|
|
|
<paramdef>const char *<parameter>message</parameter></paramdef>
|
2012-07-31 22:09:01 +08:00
|
|
|
|
</funcprototype>
|
|
|
|
|
|
2012-07-09 21:46:21 +08:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
|
|
<para><function>sd_journal_print()</function> may be
|
|
|
|
|
used to submit simple, plain text log entries to the
|
|
|
|
|
system journal. The first argument is a priority
|
|
|
|
|
value. This is followed by a format string and its
|
|
|
|
|
parameters, similar to
|
|
|
|
|
<citerefentry><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
|
or
|
|
|
|
|
<citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>. The
|
|
|
|
|
priority value is one of
|
2013-06-27 07:47:34 +08:00
|
|
|
|
<constant>LOG_EMERG</constant>,
|
|
|
|
|
<constant>LOG_ALERT</constant>,
|
|
|
|
|
<constant>LOG_CRIT</constant>,
|
|
|
|
|
<constant>LOG_ERR</constant>,
|
|
|
|
|
<constant>LOG_WARNING</constant>,
|
|
|
|
|
<constant>LOG_NOTICE</constant>,
|
|
|
|
|
<constant>LOG_INFO</constant>,
|
|
|
|
|
<constant>LOG_DEBUG</constant>, as defined in
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<filename>syslog.h</filename>, see
|
|
|
|
|
<citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
|
for details. It is recommended to use this call to
|
|
|
|
|
submit log messages in the application locale or system
|
|
|
|
|
locale and in UTF-8 format, but no such restrictions
|
|
|
|
|
are enforced.</para>
|
|
|
|
|
|
|
|
|
|
<para><function>sd_journal_printv()</function> is
|
|
|
|
|
similar to <function>sd_journal_print()</function> but
|
|
|
|
|
takes a variable argument list encapsulated in an
|
2013-06-27 07:47:34 +08:00
|
|
|
|
object of type <varname>va_list</varname> (see
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<citerefentry><refentrytitle>stdarg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
|
for more information) instead of the format string. It
|
2012-09-05 01:24:16 +08:00
|
|
|
|
is otherwise equivalent in behavior.</para>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
|
|
|
|
|
<para><function>sd_journal_send()</function> may be
|
|
|
|
|
used to submit structured log entries to the system
|
|
|
|
|
journal. It takes a series of format strings, each
|
|
|
|
|
immediately followed by their associated parameters,
|
2013-06-27 07:47:34 +08:00
|
|
|
|
terminated by <constant>NULL</constant>. The strings passed should be of
|
2012-07-09 21:46:21 +08:00
|
|
|
|
the format <literal>VARIABLE=value</literal>. The
|
2012-08-22 08:49:17 +08:00
|
|
|
|
variable name must be in uppercase and consist only of
|
|
|
|
|
characters, numbers and underscores, and may not begin
|
|
|
|
|
with an underscore. (All assignments that do not
|
|
|
|
|
follow this syntax will be ignored.) The value can be
|
|
|
|
|
of any size and format. It is highly recommended to
|
|
|
|
|
submit text strings formatted in the UTF-8 character
|
|
|
|
|
encoding only, and submit binary fields only when
|
2013-06-23 08:04:08 +08:00
|
|
|
|
formatting in UTF-8 strings is not sensible. A number
|
2012-08-22 08:49:17 +08:00
|
|
|
|
of well known fields are defined, see
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
|
|
|
|
|
for details, but additional application defined fields
|
2012-08-22 08:49:17 +08:00
|
|
|
|
may be used. A variable may be assigned more than one
|
|
|
|
|
value per entry.</para>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
|
|
|
|
|
<para><function>sd_journal_sendv()</function> is
|
|
|
|
|
similar to <function>sd_journal_send()</function> but
|
2013-06-27 07:47:34 +08:00
|
|
|
|
takes an array of <varname>struct iovec</varname> (as
|
2012-07-09 21:46:21 +08:00
|
|
|
|
defined in <filename>uio.h</filename>, see
|
|
|
|
|
<citerefentry><refentrytitle>readv</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
|
for details) instead of the format string. Each
|
|
|
|
|
structure should reference one field of the entry to
|
|
|
|
|
submit. The second argument specifies the number of
|
2014-01-26 12:35:28 +08:00
|
|
|
|
structures in the array.
|
|
|
|
|
<function>sd_journal_sendv()</function> is
|
2012-07-09 21:46:21 +08:00
|
|
|
|
particularly useful to submit binary objects to the
|
|
|
|
|
journal where that is necessary.</para>
|
|
|
|
|
|
2012-07-31 22:09:01 +08:00
|
|
|
|
<para><function>sd_journal_perror()</function> is a
|
|
|
|
|
similar to
|
|
|
|
|
<citerefentry><refentrytitle>perror</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
|
and writes a message to the journal that consists of
|
|
|
|
|
the passed string, suffixed with ": " and a human
|
|
|
|
|
readable representation of the current error code
|
|
|
|
|
stored in
|
|
|
|
|
<citerefentry><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If
|
2013-09-13 03:12:49 +08:00
|
|
|
|
the message string is passed as <constant>NULL</constant> or empty string,
|
2012-07-31 22:09:01 +08:00
|
|
|
|
only the error string representation will be written,
|
|
|
|
|
prefixed with nothing. An additional journal field
|
|
|
|
|
ERRNO= is included in the entry containing the numeric
|
|
|
|
|
error code formatted as decimal string. The log
|
2013-06-27 07:47:34 +08:00
|
|
|
|
priority used is <constant>LOG_ERR</constant> (3).</para>
|
2012-07-31 22:09:01 +08:00
|
|
|
|
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<para>Note that <function>sd_journal_send()</function>
|
2012-07-14 03:54:19 +08:00
|
|
|
|
is a wrapper around
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<function>sd_journal_sendv()</function> to make it
|
|
|
|
|
easier to use when only text strings shall be
|
|
|
|
|
submitted. Also, the following two calls are
|
|
|
|
|
mostly equivalent:</para>
|
|
|
|
|
|
|
|
|
|
<programlisting>sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
|
|
|
|
|
|
|
|
|
|
sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
|
|
|
|
|
"PRIORITY=%i", LOG_INFO,
|
|
|
|
|
NULL);</programlisting>
|
|
|
|
|
|
|
|
|
|
<para>Note that these calls implicitly add fields for
|
|
|
|
|
the source file, function name and code line where
|
|
|
|
|
invoked. This is implemented with macros. If this is
|
2013-09-13 03:12:49 +08:00
|
|
|
|
not desired, it can be turned off by defining
|
2012-07-09 21:46:21 +08:00
|
|
|
|
SD_JOURNAL_SUPPRESS_LOCATION before including
|
|
|
|
|
<filename>sd-journal.h</filename>.</para>
|
2012-07-09 22:04:21 +08:00
|
|
|
|
|
|
|
|
|
<para><citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
2012-10-26 06:16:47 +08:00
|
|
|
|
and <function>sd_journal_print()</function> may
|
2012-07-15 16:41:40 +08:00
|
|
|
|
largely be used interchangeably
|
2012-07-09 22:04:21 +08:00
|
|
|
|
functionality-wise. However, note that log messages
|
|
|
|
|
logged via the former take a different path to the
|
|
|
|
|
journal server than the later, and hence global
|
|
|
|
|
chronological ordering between the two streams cannot
|
|
|
|
|
be guaranteed. Using
|
|
|
|
|
<function>sd_journal_print()</function> has the
|
2013-06-28 03:51:44 +08:00
|
|
|
|
benefit of logging source code line, filenames, and
|
2014-02-17 10:37:18 +08:00
|
|
|
|
functions as metadata along all entries, and
|
2012-07-09 22:04:21 +08:00
|
|
|
|
guaranteeing chronological ordering with structured
|
|
|
|
|
log entries that are generated via
|
|
|
|
|
<function>sd_journal_send()</function>. Using
|
|
|
|
|
<function>syslog()</function> has the benefit of being
|
|
|
|
|
more portable.</para>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Return Value</title>
|
|
|
|
|
|
2012-07-31 22:09:01 +08:00
|
|
|
|
<para>The four calls return 0 on success or a negative
|
|
|
|
|
errno-style error code. The
|
|
|
|
|
<citerefentry><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
|
variable itself is not altered.</para>
|
2014-05-09 20:39:25 +08:00
|
|
|
|
|
|
|
|
|
<para>If
|
|
|
|
|
<citerefentry><refentrytitle>systemd-journald</refentrytitle><manvolnum>8</manvolnum></citerefentry>
|
|
|
|
|
is not running (the socket is not present), those
|
|
|
|
|
functions do nothing, and also return 0.</para>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
</refsect1>
|
|
|
|
|
|
2014-01-26 12:35:28 +08:00
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Async signal safety</title>
|
|
|
|
|
<para><function>sd_journal_sendv()</function> is "async signal
|
|
|
|
|
safe" in the meaning of <citerefentry><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para><function>sd_journal_print</function>,
|
|
|
|
|
<function>sd_journal_printv</function>,
|
|
|
|
|
<function>sd_journal_send</function>, and
|
|
|
|
|
<function>sd_journal_perror</function> are
|
|
|
|
|
not async signal safe.</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
|
|
<para>The <function>sd_journal_print()</function>,
|
|
|
|
|
<function>sd_journal_printv()</function>,
|
|
|
|
|
<function>sd_journal_send()</function> and
|
|
|
|
|
<function>sd_journal_sendv()</function> interfaces
|
2013-12-26 09:47:43 +08:00
|
|
|
|
are available as a shared library, which can be compiled
|
2012-07-09 21:46:21 +08:00
|
|
|
|
and linked to with the
|
2014-02-20 01:30:41 +08:00
|
|
|
|
<constant>libsystemd</constant> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
file.</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
2012-07-13 07:50:05 +08:00
|
|
|
|
<citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
2012-07-09 21:46:21 +08:00
|
|
|
|
<citerefentry><refentrytitle>sd_journal_stream_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
|
|
<citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
2012-07-31 22:09:01 +08:00
|
|
|
|
<citerefentry><refentrytitle>perror</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
|
|
<citerefentry><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
2014-01-26 12:35:28 +08:00
|
|
|
|
<citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
|
|
|
|
|
<citerefentry><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
|
|
|
|
|
<citerefentry><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
|
2012-07-09 21:46:21 +08:00
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
</refentry>
|