Debian Codegraph @

upstream/debian-unstable/man3/sd_journal_print.3

raw
1 '\" t
2 .TH "SD_JOURNAL_PRINT" "3" "" "systemd 261~rc3" "sd_journal_print"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_journal_print, sd_journal_printv, sd_journal_send, sd_journal_sendv, sd_journal_perror, SD_JOURNAL_SUPPRESS_LOCATION, sd_journal_print_with_location, sd_journal_printv_with_location, sd_journal_send_with_location, sd_journal_sendv_with_location, sd_journal_perror_with_location \- Submit log entries to the journal
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-journal\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_journal_print('u
32 .BI "int sd_journal_print(int\ " "priority" ", const\ char\ *" "format" ", \&...);"
33 .HP \w'int\ sd_journal_printv('u
34 .BI "int sd_journal_printv(int\ " "priority" ", const\ char\ *" "format" ", va_list\ " "ap" ");"
35 .HP \w'int\ sd_journal_send('u
36 .BI "int sd_journal_send(const\ char\ *" "format" ", \&...);"
37 .HP \w'int\ sd_journal_sendv('u
38 .BI "int sd_journal_sendv(const\ struct\ iovec\ *" "iov" ", int\ " "n" ");"
39 .HP \w'int\ sd_journal_perror('u
40 .BI "int sd_journal_perror(const\ char\ *" "message" ");"
41 .HP \w'int\ sd_journal_print_with_location('u
42 .BI "int sd_journal_print_with_location(int\ " "priority" ", const\ char\ *" "file" ", const\ char\ *" "line" ", const\ char\ *" "func" ", const\ char\ *" "format" ", \&...);"
43 .HP \w'int\ sd_journal_printv_with_location('u
44 .BI "int sd_journal_printv_with_location(int\ " "priority" ", const\ char\ *" "file" ", const\ char\ *" "line" ", const\ char\ *" "func" ", const\ char\ *" "format" ", va_list\ " "ap" ");"
45 .HP \w'int\ sd_journal_send_with_location('u
46 .BI "int sd_journal_send_with_location(const\ char\ *" "file" ", const\ char\ *" "line" ", const\ char\ *" "func" ", const\ char\ *" "format" ", \&...);"
47 .HP \w'int\ sd_journal_sendv_with_location('u
48 .BI "int sd_journal_sendv_with_location(const\ char\ *" "file" ", const\ char\ *" "line" ", const\ char\ *" "func" ", const\ struct\ iovec\ *" "iov" ", int\ " "n" ");"
49 .HP \w'int\ sd_journal_perror_with_location('u
50 .BI "int sd_journal_perror_with_location(const\ char\ *" "file" ", const\ char\ *" "line" ", const\ char\ *" "func" ", const\ char\ *" "message" ");"
51 .SH "DESCRIPTION"
52 .PP
53 \fBsd_journal_print()\fR
54 may be used to submit simple, plain text log entries to the system journal\&. The first argument is a priority value\&. This is followed by a format string and its parameters, similar to
55 \fBprintf\fR(3)
56 or
57 \fBsyslog\fR(3)\&. Note that currently the resulting message will be truncated to
58 \fBLINE_MAX \- 8\fR\&. The priority value is one of
59 \fBLOG_EMERG\fR,
60 \fBLOG_ALERT\fR,
61 \fBLOG_CRIT\fR,
62 \fBLOG_ERR\fR,
63 \fBLOG_WARNING\fR,
64 \fBLOG_NOTICE\fR,
65 \fBLOG_INFO\fR,
66 \fBLOG_DEBUG\fR, as defined in
67 syslog\&.h, see
68 \fBsyslog\fR(3)
69 for details\&. It is recommended to use this call to submit log messages in the application locale or system locale and in UTF\-8 format, but no such restrictions are enforced\&. Note that log messages written using this function are generally not expected to end in a new\-line character\&. However, as all trailing whitespace (including spaces, new\-lines, tabulators and carriage returns) are automatically stripped from the logged string, it is acceptable to specify one (or more)\&. Empty lines (after trailing whitespace removal) are suppressed\&. On non\-empty lines, leading whitespace (as well as inner whitespace) is left unmodified\&.
70 .PP
71 \fBsd_journal_printv()\fR
72 is similar to
73 \fBsd_journal_print()\fR
74 but takes a variable argument list encapsulated in an object of type
75 \fIva_list\fR
76 (see
77 \fBstdarg\fR(3)
78 for more information) instead of the format string\&. It is otherwise equivalent in behavior\&.
79 .PP
80 \fBsd_journal_send()\fR
81 may be used to submit structured log entries to the system journal\&. It takes a series of format strings, each immediately followed by their associated parameters, terminated by
82 \fBNULL\fR\&. The strings passed should be of the format
83 "VARIABLE=value"\&. The variable name must be in uppercase and consist only of characters, numbers and underscores, and may not begin with an underscore\&. (All assignments that do not follow this syntax will be ignored\&.) The value can be of any size and format\&. It is highly recommended to submit text strings formatted in the UTF\-8 character encoding only, and submit binary fields only when formatting in UTF\-8 strings is not sensible\&. A number of well\-known fields are defined, see
84 \fBsystemd.journal-fields\fR(7)
85 for details, but additional application defined fields may be used\&. A variable may be assigned more than one value per entry\&. If this function is used, trailing whitespace is automatically removed from each formatted field\&.
86 .PP
87 \fBsd_journal_sendv()\fR
88 is similar to
89 \fBsd_journal_send()\fR
90 but takes an array of
91 \fIstruct iovec\fR
92 (as defined in
93 uio\&.h, see
94 \fBreadv\fR(3)
95 for details) instead of the format string\&. Each structure should reference one field of the entry to submit\&. The second argument specifies the number of structures in the array\&.
96 \fBsd_journal_sendv()\fR
97 is particularly useful to submit binary objects to the journal where that is necessary\&. Note that this function will not strip trailing whitespace of the passed fields, but passes the specified data along unmodified\&. This is different from both
98 \fBsd_journal_print()\fR
99 and
100 \fBsd_journal_send()\fR
101 described above, which are based on format strings, and do strip trailing whitespace\&.
102 .PP
103 \fBsd_journal_perror()\fR
104 is a similar to
105 \fBperror\fR(3)
106 and writes a message to the journal that consists of the passed string, suffixed with ": " and a human\-readable representation of the current error code stored in
107 \fBerrno\fR(3)\&. If the message string is passed as
108 \fBNULL\fR
109 or empty string, only the error string representation will be written, prefixed with nothing\&. An additional journal field ERRNO= is included in the entry containing the numeric error code formatted as decimal string\&. The log priority used is
110 \fBLOG_ERR\fR
111 (3)\&.
112 .PP
113 Note that
114 \fBsd_journal_send()\fR
115 is a wrapper around
116 \fBsd_journal_sendv()\fR
117 to make it easier to use when only text strings shall be submitted\&. Also, the following two calls are mostly equivalent:
118 .sp
119 .if n \{\
120 .RS 4
121 .\}
122 .nf
123 sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
124
125 sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
126 "PRIORITY=%i", LOG_INFO,
127 NULL);
128 .fi
129 .if n \{\
130 .RE
131 .\}
132 .PP
133 Note that these calls implicitly add fields for the source file, function name and code line where invoked\&. This is implemented with macros\&. If this is not desired, it can be turned off by defining
134 \fBSD_JOURNAL_SUPPRESS_LOCATION\fR
135 before including
136 sd\-journal\&.h\&.
137 .PP
138 \fBsd_journal_print_with_location()\fR,
139 \fBsd_journal_printv_with_location()\fR,
140 \fBsd_journal_send_with_location()\fR,
141 \fBsd_journal_sendv_with_location()\fR, and
142 \fBsd_journal_perror_with_location()\fR
143 are similar to their counterparts without
144 "_with_location", but accept additional parameters to explicitly set the source file name, function, and line\&. The arguments
145 "file"
146 and
147 "line"
148 must contain valid journal entries including the variable name, e\&.g\&.
149 "CODE_FILE=src/foo\&.c"
150 and
151 "CODE_LINE=666", while
152 "func"
153 must only contain the function name, i\&.e\&. the value without
154 "CODE_FUNC="\&. These variants are primarily useful when writing custom wrappers, for example in bindings for a different language\&.
155 .PP
156 \fBsyslog\fR(3)
157 and
158 \fBsd_journal_print()\fR
159 may largely be used interchangeably functionality\-wise\&. However, note that log messages logged via the former take a different path to the journal server than the later, and hence global chronological ordering between the two streams cannot be guaranteed\&. Using
160 \fBsd_journal_print()\fR
161 has the benefit of logging source code line, filenames, and functions as metadata along all entries, and guaranteeing chronological ordering with structured log entries that are generated via
162 \fBsd_journal_send()\fR\&. Using
163 \fBsyslog()\fR
164 has the benefit of being more portable\&.
165 .PP
166 These functions implement a client to the
167 \m[blue]\fBNative Journal Protocol\fR\m[]\&\s-2\u[1]\d\s+2\&.
168 .SH "RETURN VALUE"
169 .PP
170 The ten functions return 0 on success or a negative errno\-style error code\&. The
171 \fBerrno\fR(3)
172 variable itself is not altered\&.
173 .PP
174 If
175 \fBsystemd-journald\fR(8)
176 is not running (the socket is not present), those functions do nothing, and also return 0\&.
177 .SH "THREAD SAFETY"
178 .PP
179 All functions listed here are thread\-safe and may be called in parallel from multiple threads\&.
180 .PP
181 \fBsd_journal_sendv()\fR
182 and
183 \fBsd_journal_sendv_with_location()\fR
184 are "async signal safe" in the meaning of
185 \fBsignal-safety\fR(7)\&.
186 .PP
187 \fBsd_journal_print()\fR,
188 \fBsd_journal_printv()\fR,
189 \fBsd_journal_send()\fR,
190 \fBsd_journal_perror()\fR, and their counterparts with
191 "_with_location"
192 are not async signal safe\&.
193 .SH "NOTES"
194 .PP
195 Functions described here are available as a shared library, which can be compiled against and linked to with the
196 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
197 file\&.
198 .PP
199 The code described here uses
200 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
201 \fBsetenv\fR(3)
202 from a parallel thread\&. It is recommended to only do calls to
203 \fBsetenv()\fR
204 from an early phase of the program when no other threads have been started\&.
205 .SH "HISTORY"
206 .PP
207 \fBsd_journal_print()\fR,
208 \fBsd_journal_printv()\fR,
209 \fBsd_journal_send()\fR, and
210 \fBsd_journal_sendv()\fR
211 were added in version 187\&.
212 .PP
213 \fBsd_journal_perror()\fR
214 was added in version 188\&.
215 .PP
216 \fBsd_journal_print_with_location()\fR,
217 \fBsd_journal_printv_with_location()\fR,
218 \fBsd_journal_send_with_location()\fR,
219 \fBsd_journal_sendv_with_location()\fR, and
220 \fBsd_journal_perror_with_location()\fR
221 were added in version 246\&.
222 .SH "SEE ALSO"
223 .PP
224 \fBsystemd\fR(1), \fBsd-journal\fR(3), \fBsd_journal_stream_fd\fR(3), \fBsyslog\fR(3), \fBperror\fR(3), \fBerrno\fR(3), \fBsystemd.journal-fields\fR(7), \fBsignal\fR(7), \fBsocket\fR(7)
225 .SH "NOTES"
226 .IP " 1." 4
227 Native Journal Protocol
228 .RS 4
229 \%https://systemd.io/JOURNAL_NATIVE_PROTOCOL
230 .RE