]>
Commit | Line | Data |
---|---|---|
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 | <!-- | |
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 | ||
798d3a52 ZJS |
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 <systemd/sd-journal.h></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 be used to | |
68 | create a log stream file descriptor. Log messages written to this | |
69 | file descriptor as simple newline-separated text strings are | |
70 | written to the journal. This file descriptor can be used | |
71 | internally by applications or be made standard output or standard | |
72 | error of other processes executed.</para> | |
73 | ||
74 | <para><function>sd_journal_stream_fd()</function> takes a short | |
75 | program identifier string as first argument, which will be written | |
76 | to the journal as _SYSLOG_IDENTIFIER= field for each log entry | |
77 | (see | |
78 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry> | |
79 | for more information). The second argument shall be the default | |
80 | priority level for all messages. The priority level is one of | |
81 | <constant>LOG_EMERG</constant>, <constant>LOG_ALERT</constant>, | |
82 | <constant>LOG_CRIT</constant>, <constant>LOG_ERR</constant>, | |
83 | <constant>LOG_WARNING</constant>, <constant>LOG_NOTICE</constant>, | |
84 | <constant>LOG_INFO</constant>, <constant>LOG_DEBUG</constant>, as | |
85 | defined in <filename>syslog.h</filename>, see | |
86 | <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
87 | for details. The third argument is a boolean: if true kernel-style | |
88 | log level prefixes (such as <constant>SD_WARNING</constant>) are | |
89 | interpreted, see | |
90 | <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
91 | for more information.</para> | |
92 | ||
93 | <para>It is recommended that applications log UTF-8 messages only | |
94 | with this API, but this is not enforced.</para> | |
95 | </refsect1> | |
96 | ||
97 | <refsect1> | |
98 | <title>Return Value</title> | |
99 | ||
100 | <para>The call returns a valid write-only file descriptor on | |
101 | success or a negative errno-style error code.</para> | |
102 | </refsect1> | |
103 | ||
104 | <refsect1> | |
105 | <title>Notes</title> | |
106 | ||
b17649ee | 107 | <para>Function <function>sd_journal_stream_fd()</function> is thread-safe and may be called |
a8d46a16 ZJS |
108 | from multiple threads. All calls will return the same file descriptor, although temporarily |
109 | multiple file descriptors may be open.</para> | |
110 | ||
798d3a52 ZJS |
111 | <para>The <function>sd_journal_stream_fd()</function> interface is |
112 | available as a shared library, which can be compiled and linked to | |
113 | with the | |
114 | <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
115 | file.</para> | |
116 | </refsect1> | |
117 | ||
118 | <refsect1> | |
119 | <title>Examples</title> | |
120 | ||
121 | <para>Creating a log stream suitable for | |
122 | <citerefentry project='man-pages'><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>:</para> | |
123 | ||
124 | <programlisting>#include <syslog.h> | |
a81df0ad | 125 | #include <stdio.h> |
67c3cf4f LP |
126 | #include <string.h> |
127 | #include <unistd.h> | |
a81df0ad LP |
128 | #include <systemd/sd-journal.h> |
129 | #include <systemd/sd-daemon.h> | |
130 | ||
131 | int main(int argc, char *argv[]) { | |
798d3a52 ZJS |
132 | int fd; |
133 | FILE *log; | |
134 | fd = sd_journal_stream_fd("test", LOG_INFO, 1); | |
135 | if (fd < 0) { | |
136 | fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd)); | |
137 | return 1; | |
138 | } | |
139 | log = fdopen(fd, "w"); | |
140 | if (!log) { | |
141 | fprintf(stderr, "Failed to create file object: %m\n"); | |
142 | close(fd); | |
143 | return 1; | |
144 | } | |
145 | fprintf(log, "Hello World!\n"); | |
146 | fprintf(log, SD_WARNING "This is a warning!\n"); | |
147 | fclose(log); | |
148 | return 0; | |
a81df0ad LP |
149 | }</programlisting> |
150 | ||
798d3a52 ZJS |
151 | </refsect1> |
152 | ||
153 | <refsect1> | |
154 | <title>See Also</title> | |
155 | ||
156 | <para> | |
157 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
158 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
159 | <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
160 | <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
161 | <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
162 | <citerefentry project='man-pages'><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
163 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry> | |
164 | </para> | |
165 | </refsect1> | |
a81df0ad LP |
166 | |
167 | </refentry> |