]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | <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> |
2 | a.headerlink { | |
3 | color: #c60f0f; | |
4 | font-size: 0.8em; | |
5 | padding: 0 4px 0 4px; | |
6 | text-decoration: none; | |
7 | visibility: hidden; | |
8 | } | |
9 | ||
10 | a.headerlink:hover { | |
11 | background-color: #c60f0f; | |
12 | color: white; | |
13 | } | |
14 | ||
15 | h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink { | |
16 | visibility: visible; | |
17 | } | |
18 | </style><a href="index.html">Index </a>· | |
19 | <a href="systemd.directives.html">Directives </a>· | |
20 | <a href="../python-systemd/index.html">Python </a>· | |
21 | <a href="../libudev/index.html">libudev </a>· | |
e735f4d4 MP |
22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 219</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 <systemd/sd-journal.h></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="idm139822287458016"></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 used to |
23 | submit simple, plain text log entries to the system journal. The | |
24 | first argument is a priority value. This is followed by a format | |
25 | string and its parameters, similar to | |
26 | <a href="http://man7.org/linux/man-pages/man3/printf.3.html"><span class="citerefentry"><span class="refentrytitle">printf</span>(3)</span></a> | |
27 | or | |
28 | <a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>. | |
29 | The priority value is one of | |
30 | <code class="constant">LOG_EMERG</code>, | |
31 | <code class="constant">LOG_ALERT</code>, | |
32 | <code class="constant">LOG_CRIT</code>, | |
33 | <code class="constant">LOG_ERR</code>, | |
34 | <code class="constant">LOG_WARNING</code>, | |
35 | <code class="constant">LOG_NOTICE</code>, | |
36 | <code class="constant">LOG_INFO</code>, | |
37 | <code class="constant">LOG_DEBUG</code>, as defined in | |
38 | <code class="filename">syslog.h</code>, see | |
39 | <a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a> | |
40 | for details. It is recommended to use this call to submit log | |
41 | messages in the application locale or system locale and in UTF-8 | |
42 | format, but no such restrictions are enforced.</p><p><code class="function">sd_journal_printv()</code> is similar to | |
43 | <code class="function">sd_journal_print()</code> but takes a variable | |
44 | argument list encapsulated in an object of type | |
45 | <code class="varname">va_list</code> (see | |
46 | <a href="stdarg.html"><span class="citerefentry"><span class="refentrytitle">stdarg</span>(3)</span></a> | |
47 | for more information) instead of the format string. It is | |
48 | otherwise equivalent in behavior.</p><p><code class="function">sd_journal_send()</code> may be used to submit | |
49 | structured log entries to the system journal. It takes a series of | |
50 | format strings, each immediately followed by their associated | |
51 | parameters, terminated by <code class="constant">NULL</code>. The strings | |
52 | passed should be of the format "<code class="literal">VARIABLE=value</code>". | |
53 | The variable name must be in uppercase and consist only of | |
54 | characters, numbers and underscores, and may not begin with an | |
55 | underscore. (All assignments that do not follow this syntax will | |
56 | be ignored.) The value can be of any size and format. It is highly | |
57 | recommended to submit text strings formatted in the UTF-8 | |
58 | character encoding only, and submit binary fields only when | |
59 | formatting in UTF-8 strings is not sensible. A number of well | |
60 | known fields are defined, see | |
61 | <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a> | |
62 | for details, but additional application defined fields may be | |
63 | used. A variable may be assigned more than one value per | |
64 | entry.</p><p><code class="function">sd_journal_sendv()</code> is similar to | |
65 | <code class="function">sd_journal_send()</code> but takes an array of | |
66 | <code class="varname">struct iovec</code> (as defined in | |
67 | <code class="filename">uio.h</code>, see | |
68 | <a href="readv.html"><span class="citerefentry"><span class="refentrytitle">readv</span>(3)</span></a> | |
69 | for details) instead of the format string. Each structure should | |
70 | reference one field of the entry to submit. The second argument | |
71 | specifies the number of structures in the array. | |
72 | <code class="function">sd_journal_sendv()</code> is particularly useful to | |
73 | submit binary objects to the journal where that is | |
74 | necessary.</p><p><code class="function">sd_journal_perror()</code> is a similar to | |
75 | <a href="perror.html"><span class="citerefentry"><span class="refentrytitle">perror</span>(3)</span></a> | |
76 | and writes a message to the journal that consists of the passed | |
77 | string, suffixed with ": " and a human readable representation of | |
78 | the current error code stored in | |
79 | <a href="http://man7.org/linux/man-pages/man3/errno.3.html"><span class="citerefentry"><span class="refentrytitle">errno</span>(3)</span></a>. | |
80 | If the message string is passed as <code class="constant">NULL</code> or | |
81 | empty string, only the error string representation will be | |
82 | written, prefixed with nothing. An additional journal field ERRNO= | |
83 | is included in the entry containing the numeric error code | |
84 | formatted as decimal string. The log priority used is | |
85 | <code class="constant">LOG_ERR</code> (3).</p><p>Note that <code class="function">sd_journal_send()</code> is a | |
86 | wrapper around <code class="function">sd_journal_sendv()</code> to make it | |
87 | easier to use when only text strings shall be submitted. Also, the | |
88 | following two calls are mostly equivalent:</p><pre class="programlisting">sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid()); | |
663996b3 MS |
89 | |
90 | sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(), | |
e735f4d4 MP |
91 | "PRIORITY=%i", LOG_INFO, |
92 | NULL);</pre><p>Note that these calls implicitly add fields for the source | |
93 | file, function name and code line where invoked. This is | |
94 | implemented with macros. If this is not desired, it can be turned | |
95 | off by defining SD_JOURNAL_SUPPRESS_LOCATION before including | |
96 | <code class="filename">sd-journal.h</code>.</p><p><a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a> | |
97 | and <code class="function">sd_journal_print()</code> may | |
98 | largely be used interchangeably | |
99 | functionality-wise. However, note that log messages | |
100 | logged via the former take a different path to the | |
101 | journal server than the later, and hence global | |
102 | chronological ordering between the two streams cannot | |
103 | be guaranteed. Using | |
104 | <code class="function">sd_journal_print()</code> has the | |
105 | benefit of logging source code line, filenames, and | |
106 | functions as metadata along all entries, and | |
107 | guaranteeing chronological ordering with structured | |
108 | log entries that are generated via | |
109 | <code class="function">sd_journal_send()</code>. Using | |
110 | <code class="function">syslog()</code> has the benefit of being | |
111 | more portable.</p></div><div class="refsect1"><a name="idm139822287416560"></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 errno-style | |
112 | error code. The | |
113 | <a href="http://man7.org/linux/man-pages/man3/errno.3.html"><span class="citerefentry"><span class="refentrytitle">errno</span>(3)</span></a> | |
114 | variable itself is not altered.</p><p>If | |
115 | <a href="systemd-journald.html"><span class="citerefentry"><span class="refentrytitle">systemd-journald</span>(8)</span></a> | |
116 | is not running (the socket is not present), those functions do | |
117 | nothing, and also return 0.</p></div><div class="refsect1"><a name="idm139822282448320"></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 | |
118 | safe" in the meaning of | |
119 | <a href="signal.html"><span class="citerefentry"><span class="refentrytitle">signal</span>(7)</span></a>. | |
120 | </p><p><code class="function">sd_journal_print</code>, | |
121 | <code class="function">sd_journal_printv</code>, | |
122 | <code class="function">sd_journal_send</code>, and | |
123 | <code class="function">sd_journal_perror</code> are | |
124 | not async signal safe.</p></div><div class="refsect1"><a name="idm139822282443152"></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>, | |
125 | <code class="function">sd_journal_printv()</code>, | |
126 | <code class="function">sd_journal_send()</code> and | |
127 | <code class="function">sd_journal_sendv()</code> interfaces are available | |
128 | as a shared library, which can be compiled and linked to with the | |
129 | <code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a> | |
130 | file.</p></div><div class="refsect1"><a name="idm139822282438000"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> | |
131 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, | |
132 | <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>, | |
133 | <a href="sd_journal_stream_fd.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_stream_fd</span>(3)</span></a>, | |
134 | <a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>, | |
135 | <a href="perror.html"><span class="citerefentry"><span class="refentrytitle">perror</span>(3)</span></a>, | |
136 | <a href="http://man7.org/linux/man-pages/man3/errno.3.html"><span class="citerefentry"><span class="refentrytitle">errno</span>(3)</span></a>, | |
137 | <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>, | |
138 | <a href="signal.html"><span class="citerefentry"><span class="refentrytitle">signal</span>(7)</span></a>, | |
139 | <a href="socket.html"><span class="citerefentry"><span class="refentrytitle">socket</span>(7)</span></a> | |
140 | </p></div></div></body></html> |