~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to man/sd_journal_stream_fd.3

Tags: upstream-202
ImportĀ upstreamĀ versionĀ 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
'\" t
2
 
.\"     Title: sd_journal_stream_fd
3
 
.\"    Author: Lennart Poettering <lennart@poettering.net>
4
 
.\" Generator: DocBook XSL Stylesheets v1.77.1 <http://docbook.sf.net/>
5
 
.\"      Date: 03/07/2013
6
 
.\"    Manual: sd_journal_stream_fd
7
 
.\"    Source: systemd
8
 
.\"  Language: English
9
 
.\"
10
 
.TH "SD_JOURNAL_STREAM_FD" "3" "" "systemd" "sd_journal_stream_fd"
11
 
.\" -----------------------------------------------------------------
12
 
.\" * Define some portability stuff
13
 
.\" -----------------------------------------------------------------
14
 
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
 
.\" http://bugs.debian.org/507673
16
 
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17
 
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
 
.ie \n(.g .ds Aq \(aq
19
 
.el       .ds Aq '
20
 
.\" -----------------------------------------------------------------
21
 
.\" * set default formatting
22
 
.\" -----------------------------------------------------------------
23
 
.\" disable hyphenation
24
 
.nh
25
 
.\" disable justification (adjust text to left margin only)
26
 
.ad l
27
 
.\" -----------------------------------------------------------------
28
 
.\" * MAIN CONTENT STARTS HERE *
29
 
.\" -----------------------------------------------------------------
30
 
.SH "NAME"
31
 
sd_journal_stream_fd \- Create log stream file descriptor to the journal
32
 
.SH "SYNOPSIS"
33
 
.sp
34
 
.ft B
35
 
.nf
36
 
#include <systemd/sd\-journal\&.h>
37
 
.fi
38
 
.ft
39
 
.HP \w'int\ sd_journal_stream_fd('u
40
 
.BI "int sd_journal_stream_fd(const\ char*\ " "identifier" ", int\ " "priority" ", int\ " "level_prefix" ");"
41
 
.SH "DESCRIPTION"
42
 
.PP
43
 
\fBsd_journal_stream_fd()\fR
44
 
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 STDOUT/STDERR of other processes executed\&.
45
 
.PP
46
 
\fBsd_journal_stream_fd()\fR
47
 
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
48
 
\fBsystemd.journal-fields\fR(7)
49
 
for more information)\&. The second argument shall be the default priority level for all messages\&. The priority level is one of
50
 
LOG_EMERG,
51
 
LOG_ALERT,
52
 
LOG_CRIT,
53
 
LOG_ERR,
54
 
LOG_WARNING,
55
 
LOG_NOTICE,
56
 
LOG_INFO,
57
 
LOG_DEBUG, as defined in
58
 
syslog\&.h, see
59
 
\fBsyslog\fR(3)
60
 
for details\&. The third argument is a boolean: if true kernel\-style log priority level prefixes (such as
61
 
SD_WARNING) are interpreted, see
62
 
\fBsd-daemon\fR(3)
63
 
for more information\&.
64
 
.PP
65
 
It is recommended that applications log UTF\-8 messages only with this API, but this is not enforced\&.
66
 
.SH "RETURN VALUE"
67
 
.PP
68
 
The call returns a valid write\-only file descriptor on success or a negative errno\-style error code\&.
69
 
.SH "NOTES"
70
 
.PP
71
 
The
72
 
\fBsd_journal_stream_fd()\fR
73
 
interface is available as shared library, which can be compiled and linked to with the
74
 
libsystemd\-journal
75
 
\fBpkg-config\fR(1)
76
 
file\&.
77
 
.SH "EXAMPLES"
78
 
.PP
79
 
Creating a log stream suitable for
80
 
\fBfprintf\fR(3):
81
 
.sp
82
 
.if n \{\
83
 
.RS 4
84
 
.\}
85
 
.nf
86
 
#include <syslog\&.h>
87
 
#include <stdio\&.h>
88
 
#include <string\&.h>
89
 
#include <unistd\&.h>
90
 
#include <systemd/sd\-journal\&.h>
91
 
#include <systemd/sd\-daemon\&.h>
92
 
 
93
 
int main(int argc, char *argv[]) {
94
 
        int fd;
95
 
        FILE *log;
96
 
        fd = sd_journal_stream_fd("test", LOG_INFO, 1);
97
 
        if (fd < 0) {
98
 
                fprintf(stderr, "Failed to create stream fd: %s\en", strerror(\-fd));
99
 
                return 1;
100
 
        }
101
 
        log = fdopen(fd, "w");
102
 
        if (!log) {
103
 
                fprintf(stderr, "Failed to create file object: %m\en");
104
 
                close(fd);
105
 
                return 1;
106
 
        }
107
 
        fprintf(log, "Hello World!\en");
108
 
        fprintf(log, SD_WARNING "This is a warning!\en");
109
 
        fclose(log);
110
 
        return 0;
111
 
}
112
 
.fi
113
 
.if n \{\
114
 
.RE
115
 
.\}
116
 
.SH "SEE ALSO"
117
 
.PP
118
 
 
119
 
\fBsystemd\fR(1),
120
 
\fBsd-journal\fR(3),
121
 
\fBsd-daemon\fR(3),
122
 
\fBsd_journal_print\fR(3),
123
 
\fBsyslog\fR(3),
124
 
\fBfprintf\fR(3),
125
 
\fBsystemd.journal-fields\fR(7)