]> git.proxmox.com Git - systemd.git/blame - man/sd_journal_stream_fd.html
Imported Upstream version 219
[systemd.git] / man / sd_journal_stream_fd.html
CommitLineData
663996b3
MS
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>·
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_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="idm139881645423328"></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 be used to
23 create a log stream file descriptor. Log messages written to this
24 file descriptor as simple newline-separated text strings are
25 written to the journal. This file descriptor can be used
26 internally by applications or be made standard output or standard
27 error of other processes executed.</p><p><code class="function">sd_journal_stream_fd()</code> takes a short
28 program identifier string as first argument, which will be written
29 to the journal as _SYSLOG_IDENTIFIER= field for each log entry
30 (see
31 <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
32 for more information). The second argument shall be the default
33 priority level for all messages. The priority level is one of
34 <code class="constant">LOG_EMERG</code>, <code class="constant">LOG_ALERT</code>,
35 <code class="constant">LOG_CRIT</code>, <code class="constant">LOG_ERR</code>,
36 <code class="constant">LOG_WARNING</code>, <code class="constant">LOG_NOTICE</code>,
37 <code class="constant">LOG_INFO</code>, <code class="constant">LOG_DEBUG</code>, as
38 defined in <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. The third argument is a boolean: if true kernel-style
41 log level prefixes (such as <code class="constant">SD_WARNING</code>) are
42 interpreted, see
43 <a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>
44 for more information.</p><p>It is recommended that applications log UTF-8 messages only
45 with this API, but this is not enforced.</p></div><div class="refsect1"><a name="idm139881649310304"></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
46 success or a negative errno-style error code.</p></div><div class="refsect1"><a name="idm139881649308992"></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> interface is
47 available as a shared library, which can be compiled and linked to
48 with the
49 <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>
50 file.</p></div><div class="refsect1"><a name="idm139881649305376"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples">¶</a></h2><p>Creating a log stream suitable for
51 <a href="http://man7.org/linux/man-pages/man3/fprintf.3.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>:</p><pre class="programlisting">#include &lt;syslog.h&gt;
663996b3
MS
52#include &lt;stdio.h&gt;
53#include &lt;string.h&gt;
54#include &lt;unistd.h&gt;
55#include &lt;systemd/sd-journal.h&gt;
56#include &lt;systemd/sd-daemon.h&gt;
57
58int main(int argc, char *argv[]) {
e735f4d4
MP
59 int fd;
60 FILE *log;
61 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
62 if (fd &lt; 0) {
63 fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
64 return 1;
65 }
66 log = fdopen(fd, "w");
67 if (!log) {
68 fprintf(stderr, "Failed to create file object: %m\n");
69 close(fd);
70 return 1;
71 }
72 fprintf(log, "Hello World!\n");
73 fprintf(log, SD_WARNING "This is a warning!\n");
74 fclose(log);
75 return 0;
76}</pre></div><div class="refsect1"><a name="idm139881649300656"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
77 <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
78 <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
79 <a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>,
80 <a href="sd_journal_print.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_print</span>(3)</span></a>,
81 <a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>,
82 <a href="http://man7.org/linux/man-pages/man3/fprintf.3.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>,
83 <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
84 </p></div></div></body></html>