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" >
9 This file is part of systemd.
11 Copyright 2012 Lennart Poettering
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.
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.
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/>.
27 <refentry id=
"sd_journal_stream_fd">
30 <title>sd_journal_stream_fd
</title>
31 <productname>systemd
</productname>
35 <contrib>Developer
</contrib>
36 <firstname>Lennart
</firstname>
37 <surname>Poettering
</surname>
38 <email>lennart@poettering.net
</email>
44 <refentrytitle>sd_journal_stream_fd
</refentrytitle>
45 <manvolnum>3</manvolnum>
49 <refname>sd_journal_stream_fd
</refname>
50 <refpurpose>Create log stream file descriptor to the journal
</refpurpose>
55 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
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>
68 <title>Description
</title>
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>
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
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
93 <citerefentry><refentrytitle>sd-daemon
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
94 for more information.
</para>
96 <para>It is recommended that applications log UTF-
8 messages only
97 with this API, but this is not enforced.
</para>
101 <title>Return Value
</title>
103 <para>The call returns a valid write-only file descriptor on
104 success or a negative errno-style error code.
</para>
110 <para>The
<function>sd_journal_stream_fd()
</function> interface is
111 available as a shared library, which can be compiled and linked to
113 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
118 <title>Examples
</title>
120 <para>Creating a log stream suitable for
121 <citerefentry project='man-pages'
><refentrytitle>fprintf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>:
</para>
123 <programlisting>#include
<syslog.h
>
124 #include
<stdio.h
>
125 #include
<string.h
>
126 #include
<unistd.h
>
127 #include
<systemd/sd-journal.h
>
128 #include
<systemd/sd-daemon.h
>
130 int main(int argc, char *argv[]) {
133 fd = sd_journal_stream_fd(
"test", LOG_INFO,
1);
135 fprintf(stderr,
"Failed to create stream fd: %s\n", strerror(-fd));
138 log = fdopen(fd,
"w");
140 fprintf(stderr,
"Failed to create file object: %m\n");
144 fprintf(log,
"Hello World!\n");
145 fprintf(log, SD_WARNING
"This is a warning!\n");
153 <title>See Also
</title>
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>