sd_journal_print.html 14.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_journal_print</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
    a.headerlink {
      color: #c60f0f;
      font-size: 0.8em;
      padding: 0 4px 0 4px;
      text-decoration: none;
      visibility: hidden;
    }

    a.headerlink:hover {
      background-color: #c60f0f;
      color: white;
    }

    h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
      visibility: visible;
    }
  </style><a href="index.html">Index </a>·
  <a href="systemd.directives.html">Directives </a>·
  <a href="../python-systemd/index.html">Python </a>·
  <a href="../libudev/index.html">libudev </a>·
Michael Biebl's avatar
Michael Biebl committed
22
  <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 215</span><hr><div class="refentry"><a name="sd_journal_print"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_journal_print, sd_journal_printv, sd_journal_send, sd_journal_sendv, sd_journal_perror, SD_JOURNAL_SUPPRESS_LOCATION — Submit log entries to the journal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;systemd/sd-journal.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_print</b>(</code></td><td>int <var class="pdparam">priority</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">format</var>, </td></tr><tr><td> </td><td>...<code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_printv</b>(</code></td><td>int <var class="pdparam">priority</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">format</var>, </td></tr><tr><td> </td><td>va_list <var class="pdparam">ap</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_send</b>(</code></td><td>const char *<var class="pdparam">format</var>, </td></tr><tr><td> </td><td>...<code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_sendv</b>(</code></td><td>const struct iovec *<var class="pdparam">iov</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">n</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_perror</b>(</code></td><td>const char *<var class="pdparam">message</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm214193392656"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description"></a></h2><p><code class="function">sd_journal_print()</code> may be
23 24 25 26 27 28 29 30
                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
                <a href="printf.html"><span class="citerefentry"><span class="refentrytitle">printf</span>(3)</span></a>
                or
                <a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>. The
                priority value is one of
Michael Biebl's avatar
Michael Biebl committed
31 32 33 34 35 36 37 38
                <code class="constant">LOG_EMERG</code>,
                <code class="constant">LOG_ALERT</code>,
                <code class="constant">LOG_CRIT</code>,
                <code class="constant">LOG_ERR</code>,
                <code class="constant">LOG_WARNING</code>,
                <code class="constant">LOG_NOTICE</code>,
                <code class="constant">LOG_INFO</code>,
                <code class="constant">LOG_DEBUG</code>, as defined in
39 40 41 42 43 44 45 46
                <code class="filename">syslog.h</code>, see
                <a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>
                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.</p><p><code class="function">sd_journal_printv()</code> is
                similar to <code class="function">sd_journal_print()</code> but
                takes a variable argument list encapsulated in an
Michael Biebl's avatar
Michael Biebl committed
47
                object of type <code class="varname">va_list</code> (see
48 49 50 51 52 53
                <a href="stdarg.html"><span class="citerefentry"><span class="refentrytitle">stdarg</span>(3)</span></a>
                for more information) instead of the format string. It
                is otherwise equivalent in behavior.</p><p><code class="function">sd_journal_send()</code> 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,
Michael Biebl's avatar
Michael Biebl committed
54 55
                terminated by <code class="constant">NULL</code>. The strings passed should be of
                the format "<code class="literal">VARIABLE=value</code>". The
56 57 58 59 60 61 62
                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
Michael Biebl's avatar
Michael Biebl committed
63
                formatting in UTF-8 strings is not sensible. A number
64 65 66 67 68 69
                of well known fields are defined, see
                <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
                for details, but additional application defined fields
                may be used. A variable may be assigned more than one
                value per entry.</p><p><code class="function">sd_journal_sendv()</code> is
                similar to <code class="function">sd_journal_send()</code> but
Michael Biebl's avatar
Michael Biebl committed
70
                takes an array of <code class="varname">struct iovec</code> (as
71 72 73 74 75
                defined in <code class="filename">uio.h</code>, see
                <a href="readv.html"><span class="citerefentry"><span class="refentrytitle">readv</span>(3)</span></a>
                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
76 77
                structures in the array.
                <code class="function">sd_journal_sendv()</code> is
78 79 80 81 82 83 84 85 86
                particularly useful to submit binary objects to the
                journal where that is necessary.</p><p><code class="function">sd_journal_perror()</code> is a
                similar to
                <a href="perror.html"><span class="citerefentry"><span class="refentrytitle">perror</span>(3)</span></a>
                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
                <a href="errno.html"><span class="citerefentry"><span class="refentrytitle">errno</span>(3)</span></a>. If
Michael Biebl's avatar
Michael Biebl committed
87
                the message string is passed as <code class="constant">NULL</code> or empty string,
88 89 90 91
                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
Michael Biebl's avatar
Michael Biebl committed
92
                priority used is <code class="constant">LOG_ERR</code> (3).</p><p>Note that <code class="function">sd_journal_send()</code>
93 94 95 96 97 98 99 100 101 102 103
                is a wrapper around
                <code class="function">sd_journal_sendv()</code> to make it
                easier to use when only text strings shall be
                submitted. Also, the following two calls are
                mostly equivalent:</p><pre class="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);</pre><p>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
Michael Biebl's avatar
Michael Biebl committed
104
                not desired, it can be turned off by defining
105 106 107 108 109 110 111 112 113 114
                SD_JOURNAL_SUPPRESS_LOCATION before including
                <code class="filename">sd-journal.h</code>.</p><p><a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>
                and <code class="function">sd_journal_print()</code> may
                largely be used interchangeably
                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
                <code class="function">sd_journal_print()</code> has the
Michael Biebl's avatar
Michael Biebl committed
115
                benefit of logging source code line, filenames, and
116
                functions as metadata along all entries, and
117 118 119 120
                guaranteeing chronological ordering with structured
                log entries that are generated via
                <code class="function">sd_journal_send()</code>. Using
                <code class="function">syslog()</code> has the benefit of being
Michael Biebl's avatar
Michael Biebl committed
121
                more portable.</p></div><div class="refsect1"><a name="idm214193498576"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value"></a></h2><p>The four calls return 0 on success or a negative
122 123
                errno-style error code. The
                <a href="errno.html"><span class="citerefentry"><span class="refentrytitle">errno</span>(3)</span></a>
124 125 126
                variable itself is not altered.</p><p>If
                <a href="systemd-journald.html"><span class="citerefentry"><span class="refentrytitle">systemd-journald</span>(8)</span></a>
                is not running (the socket is not present), those
Michael Biebl's avatar
Michael Biebl committed
127
                functions do nothing, and also return 0.</p></div><div class="refsect1"><a name="idm214193495056"></a><h2 id="Async signal safety">Async signal safety<a class="headerlink" title="Permalink to this headline" href="#Async%20signal%20safety"></a></h2><p><code class="function">sd_journal_sendv()</code> is "async signal
128 129 130 131 132
                safe" in the meaning of <a href="signal.html"><span class="citerefentry"><span class="refentrytitle">signal</span>(7)</span></a>.
                </p><p><code class="function">sd_journal_print</code>,
                <code class="function">sd_journal_printv</code>,
                <code class="function">sd_journal_send</code>, and
                <code class="function">sd_journal_perror</code> are
Michael Biebl's avatar
Michael Biebl committed
133
                not async signal safe.</p></div><div class="refsect1"><a name="idm214193489376"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes"></a></h2><p>The <code class="function">sd_journal_print()</code>,
134 135 136
                <code class="function">sd_journal_printv()</code>,
                <code class="function">sd_journal_send()</code> and
                <code class="function">sd_journal_sendv()</code> interfaces
137
                are available as a shared library, which can be compiled
138
                and linked to with the
139
                <code class="constant">libsystemd</code> <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
Michael Biebl's avatar
Michael Biebl committed
140
                file.</p></div><div class="refsect1"><a name="idm214188855456"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
141 142 143 144 145 146
                        <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
                        <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
                        <a href="sd_journal_stream_fd.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_stream_fd</span>(3)</span></a>,
                        <a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>,
                        <a href="perror.html"><span class="citerefentry"><span class="refentrytitle">perror</span>(3)</span></a>,
                        <a href="errno.html"><span class="citerefentry"><span class="refentrytitle">errno</span>(3)</span></a>,
147 148 149
                        <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>,
                        <a href="signal.html"><span class="citerefentry"><span class="refentrytitle">signal</span>(7)</span></a>,
                        <a href="socket.html"><span class="citerefentry"><span class="refentrytitle">socket</span>(7)</span></a>
150
                </p></div></div></body></html>