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