systemd/man/sd_journal_stream_fd.html
2015-02-17 11:22:16 +01:00

85 lines
6.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>
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>·
<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
create a log stream file descriptor. Log messages written to this
file descriptor as simple newline-separated text strings are
written to the journal. This file descriptor can be used
internally by applications or be made standard output or standard
error of other processes executed.</p><p><code class="function">sd_journal_stream_fd()</code> takes a short
program identifier string as first argument, which will be written
to the journal as _SYSLOG_IDENTIFIER= field for each log entry
(see
<a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
for more information). The second argument shall be the default
priority level for all messages. The priority level is one of
<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 <code class="filename">syslog.h</code>, see
<a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>
for details. The third argument is a boolean: if true kernel-style
log level prefixes (such as <code class="constant">SD_WARNING</code>) are
interpreted, see
<a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>
for more information.</p><p>It is recommended that applications log UTF-8 messages only
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
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
available as a shared library, which can be compiled and linked to
with the
<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>
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
<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;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;unistd.h&gt;
#include &lt;systemd/sd-journal.h&gt;
#include &lt;systemd/sd-daemon.h&gt;
int main(int argc, char *argv[]) {
int fd;
FILE *log;
fd = sd_journal_stream_fd("test", LOG_INFO, 1);
if (fd &lt; 0) {
fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
return 1;
}
log = fdopen(fd, "w");
if (!log) {
fprintf(stderr, "Failed to create file object: %m\n");
close(fd);
return 1;
}
fprintf(log, "Hello World!\n");
fprintf(log, SD_WARNING "This is a warning!\n");
fclose(log);
return 0;
}</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>
<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-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>,
<a href="sd_journal_print.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_print</span>(3)</span></a>,
<a href="http://man7.org/linux/man-pages/man3/syslog.3.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>,
<a href="http://man7.org/linux/man-pages/man3/fprintf.3.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>,
<a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>
</p></div></div></body></html>