]> git.proxmox.com Git - systemd.git/blob - man/sd_journal_stream_fd.3
Imported Upstream version 217
[systemd.git] / man / sd_journal_stream_fd.3
1 '\" t
2 .TH "SD_JOURNAL_STREAM_FD" "3" "" "systemd 217" "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 \- 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 .SH "DESCRIPTION"
34 .PP
35 \fBsd_journal_stream_fd()\fR
36 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\&.
37 .PP
38 \fBsd_journal_stream_fd()\fR
39 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
40 \fBsystemd.journal-fields\fR(7)
41 for more information)\&. The second argument shall be the default priority level for all messages\&. The priority level is one of
42 \fBLOG_EMERG\fR,
43 \fBLOG_ALERT\fR,
44 \fBLOG_CRIT\fR,
45 \fBLOG_ERR\fR,
46 \fBLOG_WARNING\fR,
47 \fBLOG_NOTICE\fR,
48 \fBLOG_INFO\fR,
49 \fBLOG_DEBUG\fR, as defined in
50 syslog\&.h, see
51 \fBsyslog\fR(3)
52 for details\&. The third argument is a boolean: if true kernel\-style log priority level prefixes (such as
53 \fBSD_WARNING\fR) are interpreted, see
54 \fBsd-daemon\fR(3)
55 for more information\&.
56 .PP
57 It is recommended that applications log UTF\-8 messages only with this API, but this is not enforced\&.
58 .SH "RETURN VALUE"
59 .PP
60 The call returns a valid write\-only file descriptor on success or a negative errno\-style error code\&.
61 .SH "NOTES"
62 .PP
63 The
64 \fBsd_journal_stream_fd()\fR
65 interface is available as a shared library, which can be compiled and linked to with the
66 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
67 file\&.
68 .SH "EXAMPLES"
69 .PP
70 Creating a log stream suitable for
71 \fBfprintf\fR(3):
72 .sp
73 .if n \{\
74 .RS 4
75 .\}
76 .nf
77 #include <syslog\&.h>
78 #include <stdio\&.h>
79 #include <string\&.h>
80 #include <unistd\&.h>
81 #include <systemd/sd\-journal\&.h>
82 #include <systemd/sd\-daemon\&.h>
83
84 int main(int argc, char *argv[]) {
85 int fd;
86 FILE *log;
87 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
88 if (fd < 0) {
89 fprintf(stderr, "Failed to create stream fd: %s\en", strerror(\-fd));
90 return 1;
91 }
92 log = fdopen(fd, "w");
93 if (!log) {
94 fprintf(stderr, "Failed to create file object: %m\en");
95 close(fd);
96 return 1;
97 }
98 fprintf(log, "Hello World!\en");
99 fprintf(log, SD_WARNING "This is a warning!\en");
100 fclose(log);
101 return 0;
102 }
103 .fi
104 .if n \{\
105 .RE
106 .\}
107 .SH "SEE ALSO"
108 .PP
109 \fBsystemd\fR(1),
110 \fBsd-journal\fR(3),
111 \fBsd-daemon\fR(3),
112 \fBsd_journal_print\fR(3),
113 \fBsyslog\fR(3),
114 \fBfprintf\fR(3),
115 \fBsystemd.journal-fields\fR(7)