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