1SD_JOURNAL_STREAM_FD(3) sd_journal_stream_fd SD_JOURNAL_STREAM_FD(3)
2
3
4
6 sd_journal_stream_fd - Create log stream file descriptor to the journal
7
9 #include <systemd/sd-journal.h>
10
11 int sd_journal_stream_fd(const char *identifier, int priority,
12 int level_prefix);
13
15 sd_journal_stream_fd() may be used to create a log stream file
16 descriptor. Log messages written to this file descriptor as simple
17 newline-separated text strings are written to the journal. This file
18 descriptor can be used internally by applications or be made standard
19 output or standard error of other processes executed.
20
21 sd_journal_stream_fd() takes a short program identifier string as first
22 argument, which will be written to the journal as _SYSLOG_IDENTIFIER=
23 field for each log entry (see systemd.journal-fields(7) for more
24 information). The second argument shall be the default priority level
25 for all messages. The priority level is one of LOG_EMERG, LOG_ALERT,
26 LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG, as
27 defined in syslog.h, see syslog(3) for details. The third argument is a
28 boolean: if true kernel-style log level prefixes (such as SD_WARNING)
29 are interpreted, see sd-daemon(3) for more information.
30
31 It is recommended that applications log UTF-8 messages only with this
32 API, but this is not enforced.
33
35 The call returns a valid write-only file descriptor on success or a
36 negative errno-style error code.
37
39 The sd_journal_stream_fd() interface is available as a shared library,
40 which can be compiled and linked to with the libsystemd pkg-config(1)
41 file.
42
44 Creating a log stream suitable for fprintf(3):
45
46 #include <syslog.h>
47 #include <stdio.h>
48 #include <string.h>
49 #include <unistd.h>
50 #include <systemd/sd-journal.h>
51 #include <systemd/sd-daemon.h>
52
53 int main(int argc, char *argv[]) {
54 int fd;
55 FILE *log;
56 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
57 if (fd < 0) {
58 fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
59 return 1;
60 }
61 log = fdopen(fd, "w");
62 if (!log) {
63 fprintf(stderr, "Failed to create file object: %m\n");
64 close(fd);
65 return 1;
66 }
67 fprintf(log, "Hello World!\n");
68 fprintf(log, SD_WARNING "This is a warning!\n");
69 fclose(log);
70 return 0;
71 }
72
74 systemd(1), sd-journal(3), sd-daemon(3), sd_journal_print(3),
75 syslog(3), fprintf(3), systemd.journal-fields(7)
76
77
78
79systemd 219 SD_JOURNAL_STREAM_FD(3)