mirror of
https://git.proxmox.com/git/systemd
synced 2026-02-03 04:18:35 +00:00
91 lines
7.1 KiB
HTML
91 lines
7.1 KiB
HTML
<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 208</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 <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_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="idm274690063392"></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 STDOUT/STDERR 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="syslog.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 priority 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="idm274693953200"></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="idm274693951888"></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 shared library, which can
|
||
be compiled and linked to with the
|
||
<code class="constant">libsystemd-journal</code> <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
|
||
file.</p></div><div class="refsect1"><a name="idm274693948544"></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="fprintf.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>:</p><pre class="programlisting">#include <syslog.h>
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <unistd.h>
|
||
#include <systemd/sd-journal.h>
|
||
#include <systemd/sd-daemon.h>
|
||
|
||
int main(int argc, char *argv[]) {
|
||
int fd;
|
||
FILE *log;
|
||
fd = sd_journal_stream_fd("test", LOG_INFO, 1);
|
||
if (fd < 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="idm274693943824"></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="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>,
|
||
<a href="fprintf.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>
|