]> git.proxmox.com Git - systemd.git/blob - man/sd_journal_stream_fd.html
Imported Upstream version 204
[systemd.git] / man / sd_journal_stream_fd.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_journal_stream_fd</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>·
22 <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 204</span><hr><div class="refentry"><a name="sd_journal_stream_fd"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_journal_stream_fd — Create log stream file descriptor 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_stream_fd</b>(</code></td><td>const char* <var class="pdparam">identifier</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">priority</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">level_prefix</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm259790662864"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description"></a></h2><p><code class="function">sd_journal_stream_fd()</code> may
23 be used to create a log stream file descriptor. Log
24 messages written to this file descriptor as simple
25 newline separated text strings are written to the
26 journal. This file descriptor can be used internally
27 by applications or be made STDOUT/STDERR of other
28 processes executed.</p><p><code class="function">sd_journal_stream_fd()</code>
29 takes a short program identifier string as first
30 argument, which will be written to the journal as
31 _SYSLOG_IDENTIFIER= field for each log entry (see
32 <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
33 for more information). The second argument shall be
34 the default priority level for all messages. The
35 priority level is one of <code class="literal">LOG_EMERG</code>,
36 <code class="literal">LOG_ALERT</code>,
37 <code class="literal">LOG_CRIT</code>,
38 <code class="literal">LOG_ERR</code>,
39 <code class="literal">LOG_WARNING</code>,
40 <code class="literal">LOG_NOTICE</code>,
41 <code class="literal">LOG_INFO</code>,
42 <code class="literal">LOG_DEBUG</code>, as defined in
43 <code class="filename">syslog.h</code>, see
44 <a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>
45 for details. The third argument is a boolean: if true
46 kernel-style log priority level prefixes (such as
47 <code class="literal">SD_WARNING</code>) are interpreted, see
48 <a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>
49 for more information.</p><p>It is recommended that applications log UTF-8
50 messages only with this API, but this is not
51 enforced.</p></div><div class="refsect1"><a name="idm259794550064"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value"></a></h2><p>The call returns a valid write-only file descriptor on success or a
52 negative errno-style error code.</p></div><div class="refsect1"><a name="idm259794548752"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes"></a></h2><p>The <code class="function">sd_journal_stream_fd()</code>
53 interface is available as shared library, which can
54 be compiled and linked to with the
55 <code class="literal">libsystemd-journal</code>
56 <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
57 file.</p></div><div class="refsect1"><a name="idm259794545120"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples"></a></h2><p>Creating a log stream suitable for
58 <a href="fprintf.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>:</p><pre class="programlisting">#include &lt;syslog.h&gt;
59 #include &lt;stdio.h&gt;
60 #include &lt;string.h&gt;
61 #include &lt;unistd.h&gt;
62 #include &lt;systemd/sd-journal.h&gt;
63 #include &lt;systemd/sd-daemon.h&gt;
64
65 int main(int argc, char *argv[]) {
66 int fd;
67 FILE *log;
68 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
69 if (fd &lt; 0) {
70 fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
71 return 1;
72 }
73 log = fdopen(fd, "w");
74 if (!log) {
75 fprintf(stderr, "Failed to create file object: %m\n");
76 close(fd);
77 return 1;
78 }
79 fprintf(log, "Hello World!\n");
80 fprintf(log, SD_WARNING "This is a warning!\n");
81 fclose(log);
82 return 0;
83 }</pre></div><div class="refsect1"><a name="idm259794540400"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
84 <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
85 <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
86 <a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>,
87 <a href="sd_journal_print.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_print</span>(3)</span></a>,
88 <a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>,
89 <a href="fprintf.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>,
90 <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
91 </p></div></div></body></html>