]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_stream_fd.xml
man: xinclude the generic text to talk about libsystemd pkgconfig
[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
a81df0ad
LP
11-->
12
7d6b2723 13<refentry id="sd_journal_stream_fd" xmlns:xi="http://www.w3.org/2001/XInclude">
a81df0ad 14
798d3a52
ZJS
15 <refentryinfo>
16 <title>sd_journal_stream_fd</title>
17 <productname>systemd</productname>
18
19 <authorgroup>
20 <author>
21 <contrib>Developer</contrib>
22 <firstname>Lennart</firstname>
23 <surname>Poettering</surname>
24 <email>lennart@poettering.net</email>
25 </author>
26 </authorgroup>
27 </refentryinfo>
28
29 <refmeta>
30 <refentrytitle>sd_journal_stream_fd</refentrytitle>
31 <manvolnum>3</manvolnum>
32 </refmeta>
33
34 <refnamediv>
35 <refname>sd_journal_stream_fd</refname>
36 <refpurpose>Create log stream file descriptor to the journal</refpurpose>
37 </refnamediv>
38
39 <refsynopsisdiv>
40 <funcsynopsis>
41 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
42
43 <funcprototype>
44 <funcdef>int <function>sd_journal_stream_fd</function></funcdef>
45 <paramdef>const char *<parameter>identifier</parameter></paramdef>
46 <paramdef>int <parameter>priority</parameter></paramdef>
47 <paramdef>int <parameter>level_prefix</parameter></paramdef>
48 </funcprototype>
49
50 </funcsynopsis>
51 </refsynopsisdiv>
52
53 <refsect1>
54 <title>Description</title>
55
56 <para><function>sd_journal_stream_fd()</function> may be used to
57 create a log stream file descriptor. Log messages written to this
58 file descriptor as simple newline-separated text strings are
59 written to the journal. This file descriptor can be used
60 internally by applications or be made standard output or standard
61 error of other processes executed.</para>
62
63 <para><function>sd_journal_stream_fd()</function> takes a short
64 program identifier string as first argument, which will be written
65 to the journal as _SYSLOG_IDENTIFIER= field for each log entry
66 (see
67 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
68 for more information). The second argument shall be the default
69 priority level for all messages. The priority level is one of
70 <constant>LOG_EMERG</constant>, <constant>LOG_ALERT</constant>,
71 <constant>LOG_CRIT</constant>, <constant>LOG_ERR</constant>,
72 <constant>LOG_WARNING</constant>, <constant>LOG_NOTICE</constant>,
73 <constant>LOG_INFO</constant>, <constant>LOG_DEBUG</constant>, as
74 defined in <filename>syslog.h</filename>, see
75 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
76 for details. The third argument is a boolean: if true kernel-style
77 log level prefixes (such as <constant>SD_WARNING</constant>) are
78 interpreted, see
79 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>
80 for more information.</para>
81
82 <para>It is recommended that applications log UTF-8 messages only
83 with this API, but this is not enforced.</para>
5b7e1d8e
LP
84
85 <para>Each invocation of <function>sd_journal_stream_fd()</function> allocates a new log stream file descriptor,
86 that is not shared with prior or later invocations. The file descriptor is write-only (its reading direction is
87 shut down), and <constant>O_NONBLOCK</constant> is turned off initially.</para>
798d3a52
ZJS
88 </refsect1>
89
90 <refsect1>
91 <title>Return Value</title>
92
93 <para>The call returns a valid write-only file descriptor on
94 success or a negative errno-style error code.</para>
95 </refsect1>
96
91ec71c1
ZJS
97 <refsect1>
98 <title>Signal safety</title>
99
2695b872
LP
100 <para><function>sd_journal_stream_fd()</function> is "async signal safe" in the meaning of <citerefentry
101 project='man-pages'><refentrytitle>signal-safety</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
91ec71c1
ZJS
102 </para>
103 </refsect1>
104
798d3a52
ZJS
105 <refsect1>
106 <title>Notes</title>
107
b17649ee 108 <para>Function <function>sd_journal_stream_fd()</function> is thread-safe and may be called
bf105e38 109 from multiple threads.</para>
a8d46a16 110
7d6b2723 111 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
798d3a52
ZJS
112 </refsect1>
113
114 <refsect1>
115 <title>Examples</title>
116
117 <para>Creating a log stream suitable for
118 <citerefentry project='man-pages'><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>:</para>
119
120 <programlisting>#include &lt;syslog.h&gt;
a81df0ad 121#include &lt;stdio.h&gt;
67c3cf4f
LP
122#include &lt;string.h&gt;
123#include &lt;unistd.h&gt;
a81df0ad
LP
124#include &lt;systemd/sd-journal.h&gt;
125#include &lt;systemd/sd-daemon.h&gt;
126
127int main(int argc, char *argv[]) {
798d3a52
ZJS
128 int fd;
129 FILE *log;
130 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
131 if (fd &lt; 0) {
132 fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
133 return 1;
134 }
135 log = fdopen(fd, "w");
136 if (!log) {
137 fprintf(stderr, "Failed to create file object: %m\n");
138 close(fd);
139 return 1;
140 }
141 fprintf(log, "Hello World!\n");
142 fprintf(log, SD_WARNING "This is a warning!\n");
143 fclose(log);
144 return 0;
a81df0ad
LP
145}</programlisting>
146
798d3a52
ZJS
147 </refsect1>
148
149 <refsect1>
150 <title>See Also</title>
151
152 <para>
153 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
154 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
155 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
156 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
157 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
158 <citerefentry project='man-pages'><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
160 </para>
161 </refsect1>
a81df0ad
LP
162
163</refentry>