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