NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |SIGNAL SAFETY |NOTES |EXAMPLES |HISTORY |SEE ALSO |COLOPHON | |
SD_JOURNAL_STREAM_FD(3) sd_journal_stream_fdSD_JOURNAL_STREAM_FD(3)sd_journal_stream_fd, sd_journal_stream_fd_with_namespace - Create log stream file descriptor to the journal
#include <systemd/sd-journal.h>int sd_journal_stream_fd(const char *identifier, intpriority,intlevel_prefix);int sd_journal_stream_fd_with_namespace(const char *name_space,const char *identifier,intpriority,intlevel_prefix);
sd_journal_stream_fd()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.sd_journal_stream_fd()takes a short program identifier string as first argument, which will be written to the journal as SYSLOG_IDENTIFIER= field for each log entry (seesystemd.journal-fields(7) for more information). The second argument shall be the default priority level for all messages. The priority level is one ofLOG_EMERG,LOG_ALERT,LOG_CRIT,LOG_ERR,LOG_WARNING,LOG_NOTICE,LOG_INFO,LOG_DEBUG, as defined in syslog.h, seesyslog(3) for details. The third argument is a boolean: if true kernel-style log level prefixes (such asSD_WARNING) are interpreted, seesd-daemon(3) for more information.sd_journal_stream_fd_with_namespace()is similar tosd_journal_stream_fd(), but takes an additionalname_space parameter that specifies which journal namespace to operate on. If specified asNULLthe call is identical tosd_journal_stream_fd(). For details about journal namespaces, seesystemd-journald.service(8). It is recommended that applications log UTF-8 messages only with this API, but this is not enforced. 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), andO_NONBLOCKis turned off initially.
The call returns a valid write-only file descriptor on success or a negative errno-style error code.
sd_journal_stream_fd()andsd_journal_stream_fd_with_namespace() are "async signal safe" in the meaning ofsignal-safety(7).
All functions listed here are thread-safe and may be called in parallel from multiple threads. Functions described here are available as a shared library, which can be compiled against and linked to with thelibsystemd pkg-config(1) file.
Creating a log stream suitable forfprintf(3): /* SPDX-License-Identifier: MIT-0 */ #define _GNU_SOURCE 1 #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) { fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd)); return 1; } log = fdopen(fd, "w"); if (!log) { fprintf(stderr, "Failed to create file object: %s\n", strerror(errno)); close(fd); return 1; } fprintf(log, "Hello World!\n"); fprintf(log, SD_WARNING "This is a warning!\n"); fclose(log); return 0; }sd_journal_stream_fd()was added in version 187.sd_journal_stream_fd_with_namespace()was added in version 256.
systemd(1),sd-journal(3),sd-daemon(3),sd_journal_print(3),syslog(3),fprintf(3),systemd.journal-fields(7)
This page is part of thesystemd (systemd system and service manager) project. Information about the project can be found at ⟨http://www.freedesktop.org/wiki/Software/systemd⟩. If you have a bug report for this manual page, see ⟨http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩. This page was obtained from the project's upstream Git repository ⟨https://github.com/systemd/systemd.git⟩ on 2025-08-11. (At that time, the date of the most recent commit that was found in the repository was 2025-08-11.) If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up-to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgsystemd 258~rc2SD_JOURNAL_STREAM_FD(3)Pages that refer to this page:sd-journal(3), sd_journal_print(3), systemd.directives(7), systemd.index(7)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |