]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_stream_fd.xml
test-hostname-util: add assert_se's to make coverity happy
[thirdparty/systemd.git] / man / sd_journal_stream_fd.xml
CommitLineData
a81df0ad
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
a81df0ad
LP
4
5<!--
572eb058
ZJS
6 SPDX-License-Identifier: LGPL-2.1+
7
a81df0ad
LP
8 This file is part of systemd.
9
10 Copyright 2012 Lennart Poettering
11
12 systemd is free software; you can redistribute it and/or modify it
13 under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 systemd is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24-->
25
26<refentry id="sd_journal_stream_fd">
27
798d3a52
ZJS
28 <refentryinfo>
29 <title>sd_journal_stream_fd</title>
30 <productname>systemd</productname>
31
32 <authorgroup>
33 <author>
34 <contrib>Developer</contrib>
35 <firstname>Lennart</firstname>
36 <surname>Poettering</surname>
37 <email>lennart@poettering.net</email>
38 </author>
39 </authorgroup>
40 </refentryinfo>
41
42 <refmeta>
43 <refentrytitle>sd_journal_stream_fd</refentrytitle>
44 <manvolnum>3</manvolnum>
45 </refmeta>
46
47 <refnamediv>
48 <refname>sd_journal_stream_fd</refname>
49 <refpurpose>Create log stream file descriptor to the journal</refpurpose>
50 </refnamediv>
51
52 <refsynopsisdiv>
53 <funcsynopsis>
54 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
55
56 <funcprototype>
57 <funcdef>int <function>sd_journal_stream_fd</function></funcdef>
58 <paramdef>const char *<parameter>identifier</parameter></paramdef>
59 <paramdef>int <parameter>priority</parameter></paramdef>
60 <paramdef>int <parameter>level_prefix</parameter></paramdef>
61 </funcprototype>
62
63 </funcsynopsis>
64 </refsynopsisdiv>
65
66 <refsect1>
67 <title>Description</title>
68
69 <para><function>sd_journal_stream_fd()</function> may be used to
70 create a log stream file descriptor. Log messages written to this
71 file descriptor as simple newline-separated text strings are
72 written to the journal. This file descriptor can be used
73 internally by applications or be made standard output or standard
74 error of other processes executed.</para>
75
76 <para><function>sd_journal_stream_fd()</function> takes a short
77 program identifier string as first argument, which will be written
78 to the journal as _SYSLOG_IDENTIFIER= field for each log entry
79 (see
80 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
81 for more information). The second argument shall be the default
82 priority level for all messages. The priority level is one of
83 <constant>LOG_EMERG</constant>, <constant>LOG_ALERT</constant>,
84 <constant>LOG_CRIT</constant>, <constant>LOG_ERR</constant>,
85 <constant>LOG_WARNING</constant>, <constant>LOG_NOTICE</constant>,
86 <constant>LOG_INFO</constant>, <constant>LOG_DEBUG</constant>, as
87 defined in <filename>syslog.h</filename>, see
88 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
89 for details. The third argument is a boolean: if true kernel-style
90 log level prefixes (such as <constant>SD_WARNING</constant>) are
91 interpreted, see
92 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>
93 for more information.</para>
94
95 <para>It is recommended that applications log UTF-8 messages only
96 with this API, but this is not enforced.</para>
97 </refsect1>
98
99 <refsect1>
100 <title>Return Value</title>
101
102 <para>The call returns a valid write-only file descriptor on
103 success or a negative errno-style error code.</para>
104 </refsect1>
105
106 <refsect1>
107 <title>Notes</title>
108
b17649ee 109 <para>Function <function>sd_journal_stream_fd()</function> is thread-safe and may be called
a8d46a16
ZJS
110 from multiple threads. All calls will return the same file descriptor, although temporarily
111 multiple file descriptors may be open.</para>
112
798d3a52
ZJS
113 <para>The <function>sd_journal_stream_fd()</function> interface is
114 available as a shared library, which can be compiled and linked to
115 with the
116 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
117 file.</para>
118 </refsect1>
119
120 <refsect1>
121 <title>Examples</title>
122
123 <para>Creating a log stream suitable for
124 <citerefentry project='man-pages'><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>:</para>
125
126 <programlisting>#include &lt;syslog.h&gt;
a81df0ad 127#include &lt;stdio.h&gt;
67c3cf4f
LP
128#include &lt;string.h&gt;
129#include &lt;unistd.h&gt;
a81df0ad
LP
130#include &lt;systemd/sd-journal.h&gt;
131#include &lt;systemd/sd-daemon.h&gt;
132
133int main(int argc, char *argv[]) {
798d3a52
ZJS
134 int fd;
135 FILE *log;
136 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
137 if (fd &lt; 0) {
138 fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
139 return 1;
140 }
141 log = fdopen(fd, "w");
142 if (!log) {
143 fprintf(stderr, "Failed to create file object: %m\n");
144 close(fd);
145 return 1;
146 }
147 fprintf(log, "Hello World!\n");
148 fprintf(log, SD_WARNING "This is a warning!\n");
149 fclose(log);
150 return 0;
a81df0ad
LP
151}</programlisting>
152
798d3a52
ZJS
153 </refsect1>
154
155 <refsect1>
156 <title>See Also</title>
157
158 <para>
159 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
163 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
164 <citerefentry project='man-pages'><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
165 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
166 </para>
167 </refsect1>
a81df0ad
LP
168
169</refentry>