'\" t .TH "SD_JOURNAL_STREAM_FD" "3" "" "systemd 256.8" "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, sd_journal_stream_fd_with_namespace \- Create log stream file descriptor to the journal .SH "SYNOPSIS" .sp .ft B .nf #include .fi .ft .HP \w'int\ sd_journal_stream_fd('u .BI "int sd_journal_stream_fd(const\ char\ *" "identifier" ", int\ " "priority" ", int\ " "level_prefix" ");" .HP \w'int\ sd_journal_stream_fd_with_namespace('u .BI "int sd_journal_stream_fd_with_namespace(const\ char\ *" "name_space" ", 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 \fBsd_journal_stream_fd_with_namespace()\fR is similar to \fBsd_journal_stream_fd()\fR, but takes an additional \fIname_space\fR parameter that specifies which journal namespace to operate on\&. If specified as \fBNULL\fR the call is identical to \fBsd_journal_stream_fd()\fR\&. For details about journal namespaces, see \fBsystemd-journald.service\fR(8)\&. .PP It is recommended that applications log UTF\-8 messages only with this API, but this is not enforced\&. .PP 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 \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 and \fBsd_journal_stream_fd_with_namespace()\fR are "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 */ #define _GNU_SOURCE 1 #include #include #include #include #include #include int main(int argc, char *argv[]) { int fd; FILE *log; fd = sd_journal_stream_fd("test", LOG_INFO, 1); if (fd < 0) { fprintf(stderr, "Failed to create stream fd: %s\en", strerror(\-fd)); return 1; } log = fdopen(fd, "w"); if (!log) { fprintf(stderr, "Failed to create file object: %s\en", strerror(errno)); 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\&. .PP \fBsd_journal_stream_fd_with_namespace()\fR was added in version 256\&. .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)