mirror of
https://git.proxmox.com/git/systemd
synced 2025-06-04 02:33:42 +00:00
116 lines
3.6 KiB
Groff
116 lines
3.6 KiB
Groff
'\" t
|
|
.TH "SD_JOURNAL_STREAM_FD" "3" "" "systemd 219" "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 \- Create log stream file descriptor to the journal
|
|
.SH "SYNOPSIS"
|
|
.sp
|
|
.ft B
|
|
.nf
|
|
#include <systemd/sd\-journal\&.h>
|
|
.fi
|
|
.ft
|
|
.HP \w'int\ sd_journal_stream_fd('u
|
|
.BI "int sd_journal_stream_fd(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
|
|
It is recommended that applications log UTF\-8 messages only with this API, but this is not enforced\&.
|
|
.SH "RETURN VALUE"
|
|
.PP
|
|
The call returns a valid write\-only file descriptor on success or a negative errno\-style error code\&.
|
|
.SH "NOTES"
|
|
.PP
|
|
The
|
|
\fBsd_journal_stream_fd()\fR
|
|
interface is available as a shared library, which can be compiled 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
|
|
#include <syslog\&.h>
|
|
#include <stdio\&.h>
|
|
#include <string\&.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\en", strerror(\-fd));
|
|
return 1;
|
|
}
|
|
log = fdopen(fd, "w");
|
|
if (!log) {
|
|
fprintf(stderr, "Failed to create file object: %m\en");
|
|
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 "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)
|