File: sd_journal_stream_fd.html

package info (click to toggle)
systemd 215-17
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 49,568 kB
  • sloc: ansic: 192,789; xml: 39,586; sh: 13,002; makefile: 4,700; perl: 1,461; python: 1,355
file content (90 lines) | stat: -rw-r--r-- 7,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<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 215</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="idm214173639024"></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="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="idm214173632368"></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="idm214173631056"></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="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
                file.</p></div><div class="refsect1"><a name="idm214173627664"></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 &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="idm214173625024"></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>