Debian Codegraph @

upstream/debian-unstable/man3/sd_journal_stream_fd.3

raw
1 '\" t
2 .TH "SD_JOURNAL_STREAM_FD" "3" "" "systemd 261~rc3" "sd_journal_stream_fd"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_journal_stream_fd, sd_journal_stream_fd_with_namespace \- Create log stream file descriptor to the journal
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-journal\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_journal_stream_fd('u
32 .BI "int sd_journal_stream_fd(const\ char\ *" "identifier" ", int\ " "priority" ", int\ " "level_prefix" ");"
33 .HP \w'int\ sd_journal_stream_fd_with_namespace('u
34 .BI "int sd_journal_stream_fd_with_namespace(const\ char\ *" "name_space" ", const\ char\ *" "identifier" ", int\ " "priority" ", int\ " "level_prefix" ");"
35 .SH "DESCRIPTION"
36 .PP
37 \fBsd_journal_stream_fd()\fR
38 may be used to create a log stream file descriptor\&. Log messages written to this file descriptor as simple newline\-separated text strings are written to the journal\&. This file descriptor can be used internally by applications or be made standard output or standard error of other processes executed\&.
39 .PP
40 \fBsd_journal_stream_fd()\fR
41 takes a short program identifier string as first argument, which will be written to the journal as SYSLOG_IDENTIFIER= field for each log entry (see
42 \fBsystemd.journal-fields\fR(7)
43 for more information)\&. The second argument shall be the default priority level for all messages\&. The priority level is one of
44 \fBLOG_EMERG\fR,
45 \fBLOG_ALERT\fR,
46 \fBLOG_CRIT\fR,
47 \fBLOG_ERR\fR,
48 \fBLOG_WARNING\fR,
49 \fBLOG_NOTICE\fR,
50 \fBLOG_INFO\fR,
51 \fBLOG_DEBUG\fR, as defined in
52 syslog\&.h, see
53 \fBsyslog\fR(3)
54 for details\&. The third argument is a boolean: if true kernel\-style log level prefixes (such as
55 \fBSD_WARNING\fR) are interpreted, see
56 \fBsd-daemon\fR(3)
57 for more information\&.
58 .PP
59 \fBsd_journal_stream_fd_with_namespace()\fR
60 is similar to
61 \fBsd_journal_stream_fd()\fR, but takes an additional
62 \fIname_space\fR
63 parameter that specifies which journal namespace to operate on\&. If specified as
64 \fBNULL\fR
65 the call is identical to
66 \fBsd_journal_stream_fd()\fR\&. For details about journal namespaces, see
67 \fBsystemd-journald.service\fR(8)\&.
68 .PP
69 It is recommended that applications log UTF\-8 messages only with this API, but this is not enforced\&.
70 .PP
71 Each invocation of these functions allocates a new log stream file descriptor, that is not shared with prior or later invocations\&. The file descriptor is write\-only (its reading direction is shut down), and
72 \fBO_NONBLOCK\fR
73 is turned off initially\&.
74 .SH "RETURN VALUE"
75 .PP
76 The call returns a valid write\-only file descriptor on success or a negative errno\-style error code\&.
77 .SH "SIGNAL SAFETY"
78 .PP
79 \fBsd_journal_stream_fd()\fR
80 and
81 \fBsd_journal_stream_fd_with_namespace()\fR
82 are "async signal safe" in the meaning of
83 \fBsignal-safety\fR(7)\&.
84 .SH "NOTES"
85 .PP
86 All functions listed here are thread\-safe and may be called in parallel from multiple threads\&.
87 .PP
88 Functions described here are available as a shared library, which can be compiled against and linked to with the
89 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
90 file\&.
91 .SH "EXAMPLES"
92 .PP
93 Creating a log stream suitable for
94 \fBfprintf\fR(3):
95 .sp
96 .if n \{\
97 .RS 4
98 .\}
99 .nf
100 /* SPDX\-License\-Identifier: MIT\-0 */
101
102 #define _GNU_SOURCE 1
103 #include <errno\&.h>
104 #include <syslog\&.h>
105 #include <stdio\&.h>
106 #include <unistd\&.h>
107 #include <systemd/sd\-journal\&.h>
108 #include <systemd/sd\-daemon\&.h>
109
110 int main(int argc, char *argv[]) {
111 int fd;
112 FILE *log;
113
114 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
115 if (fd < 0) {
116 fprintf(stderr, "Failed to create stream fd: %s\en", strerror(\-fd));
117 return 1;
118 }
119
120 log = fdopen(fd, "w");
121 if (!log) {
122 fprintf(stderr, "Failed to create file object: %s\en", strerror(errno));
123 close(fd);
124 return 1;
125 }
126 fprintf(log, "Hello World!\en");
127 fprintf(log, SD_WARNING "This is a warning!\en");
128 fclose(log);
129 return 0;
130 }
131 .fi
132 .if n \{\
133 .RE
134 .\}
135 .SH "HISTORY"
136 .PP
137 \fBsd_journal_stream_fd()\fR
138 was added in version 187\&.
139 .PP
140 \fBsd_journal_stream_fd_with_namespace()\fR
141 was added in version 256\&.
142 .SH "SEE ALSO"
143 .PP
144 \fBsystemd\fR(1), \fBsd-journal\fR(3), \fBsd-daemon\fR(3), \fBsd_journal_print\fR(3), \fBsyslog\fR(3), \fBfprintf\fR(3), \fBsystemd.journal-fields\fR(7)