1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
.\" Written Feb 1994 by Steve Greenland (stevegr@neosoft.com)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Updated 1999.12.19 by Karl M. Hegbloom <karlheg@debian.org>
.\"
.\" Updated 13 Oct 2001, Michael Kerrisk <mtk.manpages@gmail.com>
.\" Added description of vsyslog
.\" Added descriptions of LOG_ODELAY and LOG_NOWAIT
.\" Added brief description of facility and option arguments
.\" Added CONFORMING TO section
.\" 2001-10-13, aeb, minor changes
.\" Modified 13 Dec 2001, Martin Schulze <joey@infodrom.org>
.\" Modified 3 Jan 2002, Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.TH SYSLOG 3 2008-11-12 "Linux" "Linux Programmer's Manual"
.SH NAME
closelog, openlog, syslog, vsyslog \- send messages to the system logger
.SH SYNOPSIS
.B #include <syslog.h>
.sp
.BI "void openlog(const char *" ident ", int " option ", int " facility );
.br
.BI "void syslog(int " priority ", const char *" format ", ...);"
.br
.B "void closelog(void);"
.sp
.B #include <stdarg.h>
.sp
.BI "void vsyslog(int " priority ", const char *" format ", va_list " ap );
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
.sp
.BR vsyslog ():
_BSD_SOURCE
.SH DESCRIPTION
.BR closelog ()
closes the descriptor being used to write to the system logger.
The use of
.BR closelog ()
is optional.
.sp
.BR openlog ()
opens a connection to the system logger for a program.
The string pointed to by
.I ident
is prepended to every message, and is typically set to the program name.
The
.I option
argument specifies flags which control the operation of
.BR openlog ()
and subsequent calls to
.BR syslog ().
The
.I facility
argument establishes a default to be used if
none is specified in subsequent calls to
.BR syslog ().
Values for
.I option
and
.I facility
are given below.
The use of
.BR openlog ()
is optional; it will automatically be called by
.BR syslog ()
if necessary, in which case
.I ident
will default to NULL.
.sp
.BR syslog ()
generates a log message, which will be distributed by
.BR syslogd (8).
The
.I priority
argument is formed by ORing the
.I facility
and the
.I level
values (explained below).
The remaining arguments
are a
.IR format ,
as in
.BR printf (3)
and any arguments required by the
.IR format ,
except that the two character sequence
.B %m
will be replaced by
the error message string
.IR strerror ( errno ).
A trailing newline may be added if needed.
The function
.BR vsyslog ()
performs the same task as
.BR syslog ()
with the difference that it takes a set of arguments which have
been obtained using the
.BR stdarg (3)
variable argument list macros.
The subsections below list the parameters used to set the values of
.IR option , " facility" ", and " priority .
.SS option
The
.I option
argument to
.BR openlog ()
is an OR of any of these:
.TP 15
.B LOG_CONS
Write directly to system console if there is an error while sending to
system logger.
.TP
.B LOG_NDELAY
Open the connection immediately (normally, the connection is opened when
the first message is logged).
.TP
.B LOG_NOWAIT
Don't wait for child processes that may have been created while logging
the message.
(The GNU C library does not create a child process, so this
option has no effect on Linux.)
.TP
.B LOG_ODELAY
The converse of
.BR LOG_NDELAY ;
opening of the connection is delayed until
.BR syslog ()
is called.
(This is the default, and need not be specified.)
.TP
.B LOG_PERROR
(Not in POSIX.1-2001.)
Print to \fIstderr\fP as well.
.TP
.B LOG_PID
Include PID with each message.
.SS facility
The
.I facility
argument is used to specify what type of program is logging the message.
This lets the configuration file specify that messages from different
facilities will be handled differently.
.TP 15
.B LOG_AUTH
security/authorization messages (DEPRECATED Use
.B LOG_AUTHPRIV
instead)
.TP
.B LOG_AUTHPRIV
security/authorization messages (private)
.TP
.B LOG_CRON
clock daemon
.RB ( cron " and " at )
.TP
.B LOG_DAEMON
system daemons without separate facility value
.TP
.B LOG_FTP
ftp daemon
.TP
.B LOG_KERN
kernel messages (these can't be generated from user processes)
.\" LOG_KERN has the value 0; if used as a facility, zero translates to:
.\" "use the default facility".
.TP
.BR LOG_LOCAL0 " through " LOG_LOCAL7
reserved for local use
.TP
.B LOG_LPR
line printer subsystem
.TP
.B LOG_MAIL
mail subsystem
.TP
.B LOG_NEWS
USENET news subsystem
.TP
.B LOG_SYSLOG
messages generated internally by
.BR syslogd (8)
.TP
.BR LOG_USER " (default)"
generic user-level messages
.TP
.B LOG_UUCP
UUCP subsystem
.SS level
This determines the importance of the message.
The levels are, in order of decreasing importance:
.TP 15
.B LOG_EMERG
system is unusable
.TP
.B LOG_ALERT
action must be taken immediately
.TP
.B LOG_CRIT
critical conditions
.TP
.B LOG_ERR
error conditions
.TP
.B LOG_WARNING
warning conditions
.TP
.B LOG_NOTICE
normal, but significant, condition
.TP
.B LOG_INFO
informational message
.TP
.B LOG_DEBUG
debug-level message
.LP
The function
.BR setlogmask (3)
can be used to restrict logging to specified levels only.
.SH "CONFORMING TO"
The functions
.BR openlog (),
.BR closelog (),
and
.BR syslog ()
(but not
.BR vsyslog ())
are specified in SUSv2 and POSIX.1-2001.
POSIX.1-2001 specifies only the
.B LOG_USER
and
.B LOG_LOCAL*
values for
.IR facility .
However, with the exception of
.B LOG_AUTHPRIV
and
.BR LOG_FTP ,
the other
.I facility
values appear on most Unix systems.
The
.B LOG_PERROR
value for
.I option
is not specified by POSIX.1-2001, but is available
in most versions of Unix.
.\" .SH HISTORY
.\" A
.\" .BR syslog ()
.\" function call appeared in 4.2BSD.
.\" 4.3BSD documents
.\" .BR openlog (),
.\" .BR syslog (),
.\" .BR closelog (),
.\" and
.\" .BR setlogmask ().
.\" 4.3BSD-Reno also documents
.\" .BR vsyslog ().
.\" Of course early v* functions used the
.\" .I <varargs.h>
.\" mechanism, which is not compatible with
.\" .IR <stdarg.h> .
.SH NOTES
The argument
.I ident
in the call of
.BR openlog ()
is probably stored as-is.
Thus, if the string it points to
is changed,
.BR syslog ()
may start prepending the changed string, and if the string
it points to ceases to exist, the results are undefined.
Most portable is to use a string constant.
.LP
Never pass a string with user-supplied data as a format,
use the following instead:
.nf
syslog(priority, "%s", string);
.fi
.SH "SEE ALSO"
.BR logger (1),
.BR setlogmask (3),
.BR syslog.conf (5),
.BR syslogd (8)
|