1SD_JOURNAL_STREAM_FD(3)      sd_journal_stream_fd      SD_JOURNAL_STREAM_FD(3)
2
3
4

NAME

6       sd_journal_stream_fd - Create log stream file descriptor to the journal
7

SYNOPSIS

9       #include <systemd/sd-journal.h>
10
11       int sd_journal_stream_fd(const char *identifier, int priority,
12                                int level_prefix);
13

DESCRIPTION

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
34       Each invocation of sd_journal_stream_fd() allocates a new log stream
35       file descriptor, that is not shared with prior or later invocations.
36       The file descriptor is write-only (its reading direction is shut down),
37       and O_NONBLOCK is turned off initially.
38

RETURN VALUE

40       The call returns a valid write-only file descriptor on success or a
41       negative errno-style error code.
42

SIGNAL SAFETY

44       sd_journal_stream_fd() is "async signal safe" in the meaning of signal-
45       safety(7).
46

NOTES

48       All functions listed here are thread-safe and may be called in parallel
49       from multiple threads.
50
51       These APIs are implemented as a shared library, which can be compiled
52       and linked to with the libsystemd pkg-config(1) file.
53

EXAMPLES

55       Creating a log stream suitable for fprintf(3):
56
57           #include <syslog.h>
58           #include <stdio.h>
59           #include <string.h>
60           #include <unistd.h>
61           #include <systemd/sd-journal.h>
62           #include <systemd/sd-daemon.h>
63
64           int main(int argc, char *argv[]) {
65             int fd;
66             FILE *log;
67             fd = sd_journal_stream_fd("test", LOG_INFO, 1);
68             if (fd < 0) {
69               fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
70               return 1;
71             }
72             log = fdopen(fd, "w");
73             if (!log) {
74               fprintf(stderr, "Failed to create file object: %m\n");
75               close(fd);
76               return 1;
77             }
78             fprintf(log, "Hello World!\n");
79             fprintf(log, SD_WARNING "This is a warning!\n");
80             fclose(log);
81             return 0;
82           }
83

SEE ALSO

85       systemd(1), sd-journal(3), sd-daemon(3), sd_journal_print(3),
86       syslog(3), fprintf(3), systemd.journal-fields(7)
87
88
89
90systemd 246                                            SD_JOURNAL_STREAM_FD(3)
Impressum