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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
'\" te
.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright (c) 1983 Regents of the University of California. All rights reserved. The Berkeley software License Agreement specifies the terms and conditions for redistribution.
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/.
.\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
.\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
.\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
.\" This notice shall appear on any product containing this material.
.TH syslog 3C "16 Mar 2009" "SunOS 5.11" "Standard C Library Functions"
.SH NAME
syslog, openlog, closelog, setlogmask \- control system log
.SH SYNOPSIS
.LP
.nf
#include <syslog.h>
\fBvoid\fR \fBopenlog\fR(\fBconst char *\fR\fIident\fR, \fBint\fR \fIlogopt\fR, \fBint\fR \fIfacility\fR);
.fi
.LP
.nf
\fBvoid\fR \fBsyslog\fR(\fBint\fR \fIpriority\fR, \fBconst char *\fR\fImessage\fR, \fB\&.../*\fR \fIarguments\fR */);
.fi
.LP
.nf
\fBvoid\fR \fBcloselog\fR(\fBvoid\fR);
.fi
.LP
.nf
\fBint\fR \fBsetlogmask\fR(\fBint\fR \fImaskpri\fR);
.fi
.SH DESCRIPTION
.sp
.LP
The \fBsyslog()\fR function sends a message to \fBsyslogd\fR(1M), which,
depending on the configuration of \fB/etc/syslog.conf\fR, logs it in an
appropriate system log, writes it to the system console, forwards it to a list
of users, or forwards it to \fBsyslogd\fR on another host over the network.
The logged message includes a message header and a message body. The message
header consists of a facility indicator, a severity level indicator, a
timestamp, a tag string, and optionally the process ID.
.sp
.LP
The message body is generated from the \fImessage\fR and following arguments in
the same manner as if these were arguments to \fBprintf\fR(3UCB), except that
occurrences of \fB%m\fR in the format string pointed to by the \fImessage\fR
argument are replaced by the error message string associated with the current
value of \fBerrno\fR. A trailing \fBNEWLINE\fR character is added if needed.
.sp
.LP
Symbolic constants for use as values of the \fIlogopt\fR, \fIfacility\fR,
\fIpriority\fR, and \fImaskpri\fR arguments are defined in the <\fBsyslog.h\fR>
header.
.sp
.LP
Values of the \fIpriority\fR argument are formed by ORing together a
\fIseverity level\fR value and an optional \fIfacility\fR value. If no
facility value is specified, the current default facility value is used.
.sp
.LP
Possible values of severity level include, in decreasing order:
.sp
.ne 2
.mk
.na
\fB\fBLOG_EMERG\fR\fR
.ad
.RS 15n
.rt
A panic condition. This is normally broadcast to all users.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_ALERT\fR\fR
.ad
.RS 15n
.rt
A condition that should be corrected immediately, such as a corrupted system
database.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_CRIT\fR\fR
.ad
.RS 15n
.rt
Critical conditions, such as hard device errors.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_ERR\fR\fR
.ad
.RS 15n
.rt
Errors.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_WARNING\fR\fR
.ad
.RS 15n
.rt
Warning messages.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_NOTICE\fR\fR
.ad
.RS 15n
.rt
Conditions that are not error conditions, but that may require special
handling.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_INFO\fR\fR
.ad
.RS 15n
.rt
Informational messages.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_DEBUG\fR\fR
.ad
.RS 15n
.rt
Messages that contain information normally of use only when debugging a
program.
.RE
.sp
.LP
The facility indicates the application or system component generating the
message. Possible facility values include:
.sp
.ne 2
.mk
.na
\fB\fBLOG_KERN\fR\fR
.ad
.RS 14n
.rt
Messages generated by the kernel. These cannot be generated by any user
processes.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_USER\fR\fR
.ad
.RS 14n
.rt
Messages generated by random user processes. This is the default facility
identifier if none is specified.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_MAIL\fR\fR
.ad
.RS 14n
.rt
The mail system.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_DAEMON\fR\fR
.ad
.RS 14n
.rt
System daemons, such as \fBin.ftpd\fR(1M).
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_AUTH\fR\fR
.ad
.RS 14n
.rt
The authentication / security / authorization system: \fBlogin\fR(1),
\fBsu\fR(1M), \fBgetty\fR(1M).
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LPR\fR\fR
.ad
.RS 14n
.rt
The line printer spooling system: \fBlpr\fR(1B), \fBlpc\fR(1B).
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_NEWS\fR\fR
.ad
.RS 14n
.rt
Designated for the \fBUSENET\fR network news system.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_UUCP\fR\fR
.ad
.RS 14n
.rt
Designated for the \fBUUCP\fR system; it does not currently use \fBsyslog()\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_CRON\fR\fR
.ad
.RS 14n
.rt
The \fBcron\fR/\fBat\fR facility; \fBcrontab\fR(1), \fBat\fR(1),
\fBcron\fR(1M).
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_AUDIT\fR\fR
.ad
.RS 14n
.rt
The audit facility, for example, \fBauditd\fR(1M).
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL0\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL1\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL2\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL3\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL4\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL5\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL6\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_LOCAL7\fR\fR
.ad
.RS 14n
.rt
Designated for local use.
.RE
.sp
.LP
The \fBopenlog()\fR function sets process attributes that affect subsequent
calls to \fBsyslog()\fR. The \fIident\fR argument is a string that is prepended
to every message. The \fBopenlog()\fR function uses the passed-in \fIident\fR
argument directly, rather than making a private copy of it. The \fIlogopt\fR
argument indicates logging options. Values for \fIlogopt\fR are constructed by
a bitwise-inclusive OR of zero or more of the following:
.sp
.ne 2
.mk
.na
\fB\fBLOG_PID\fR\fR
.ad
.RS 14n
.rt
Log the process \fBID\fR with each message. This is useful for identifying
specific daemon processes (for daemons that fork).
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_CONS\fR\fR
.ad
.RS 14n
.rt
Write messages to the system console if they cannot be sent to
\fBsyslogd\fR(1M). This option is safe to use in daemon processes that have no
controlling terminal, since \fBsyslog()\fR forks before opening the console.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_NDELAY\fR\fR
.ad
.RS 14n
.rt
Open the connection to \fBsyslogd\fR(1M) immediately. Normally the open is
delayed until the first message is logged. This is useful for programs that
need to manage the order in which file descriptors are allocated.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_ODELAY\fR\fR
.ad
.RS 14n
.rt
Delay open until \fBsyslog()\fR is called.
.RE
.sp
.ne 2
.mk
.na
\fB\fBLOG_NOWAIT\fR\fR
.ad
.RS 14n
.rt
Do not wait for child processes that have been forked to log messages onto the
console. This option should be used by processes that enable notification of
child termination using \fBSIGCHLD\fR, since \fBsyslog()\fR may otherwise block
waiting for a child whose exit status has already been collected.
.RE
.sp
.LP
The \fIfacility\fR argument encodes a default facility to be assigned to all
messages that do not have an explicit facility already encoded. The initial
default facility is \fBLOG_USER\fR.
.sp
.LP
The \fBopenlog()\fR and \fBsyslog()\fR functions may allocate a file
descriptor. It is not necessary to call \fBopenlog()\fR prior to calling
\fBsyslog()\fR.
.sp
.LP
The \fBcloselog()\fR function closes any open file descriptors allocated by
previous calls to \fBopenlog()\fR or \fBsyslog()\fR.
.sp
.LP
The \fBsetlogmask()\fR function sets the log priority mask for the current
process to \fImaskpri\fR and returns the previous mask. If the \fImaskpri\fR
argument is 0, the current log mask is not modified. Calls by the current
process to \fBsyslog()\fR with a priority not set in \fImaskpri\fR are
rejected. The mask for an individual priority \fIpri\fR is calculated by the
macro \fBLOG_MASK(\fIpri\fR)\fR; the mask for all priorities up to and
including \fItoppri\fR is given by the macro \fBLOG_UPTO(\fItoppri\fR)\fR. The
default log mask allows all priorities to be logged.
.SH RETURN VALUES
.sp
.LP
The \fBsetlogmask()\fR function returns the previous log priority mask. The
\fBcloselog()\fR, \fBopenlog()\fR and \fBsyslog()\fR functions return no value.
.SH ERRORS
.sp
.LP
No errors are defined.
.SH EXAMPLES
.LP
\fBExample 1 \fRExample of \fBLOG_ALERT\fR message.
.sp
.LP
This call logs a message at priority \fBLOG_ALERT\fR:
.sp
.in +2
.nf
\fBsyslog(LOG_ALERT, "who: internal error 23")\fR;
.fi
.in -2
.sp
.sp
.LP
The \fBFTP\fR daemon \fBftpd\fR would make this call to \fBopenlog()\fR to
indicate that all messages it logs should have an identifying string of
\fBftpd\fR, should be treated by \fBsyslogd\fR(1M) as other messages from
system daemons are, should include the process \fBID\fR of the process logging
the message:
.sp
.in +2
.nf
\fBopenlog("ftpd", LOG_PID, LOG_DAEMON)\fR;
.fi
.in -2
.sp
.sp
.LP
Then it would make the following call to \fBsetlogmask()\fR to indicate that
messages at priorities from \fBLOG_EMERG\fR through \fBLOG_ERR\fR should be
logged, but that no messages at any other priority should be logged:
.sp
.in +2
.nf
\fBsetlogmask(LOG_UPTO(LOG_ERR))\fR;
.fi
.in -2
.sp
.sp
.LP
Then, to log a message at priority \fBLOG_INFO\fR, it would make the following
call to \fBsyslog\fR:
.sp
.in +2
.nf
\fBsyslog(LOG_INFO, "Connection from host %d", CallingHost)\fR;
.fi
.in -2
.sp
.sp
.LP
A locally-written utility could use the following call to \fBsyslog()\fR to log
a message at priority \fBLOG_INFO\fR to be treated by \fBsyslogd\fR(1M) as
other messages to the facility \fBLOG_LOCAL2\fR are:
.sp
.in +2
.nf
\fBsyslog(LOG_INFO|LOG_LOCAL2, "error: %m")\fR;
.fi
.in -2
.sp
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
Interface StabilityCommitted
_
MT-LevelSafe
_
StandardSee \fBstandards\fR(5).
.TE
.SH SEE ALSO
.sp
.LP
\fBat\fR(1), \fBcrontab\fR(1), \fBlogger\fR(1), \fBlogin\fR(1), \fBlpc\fR(1B),
\fBlpr\fR(1B), \fBauditd\fR(1M), \fBcron\fR(1M), \fBgetty\fR(1M),
\fBin.ftpd\fR(1M), \fBsu\fR(1M), \fBsyslogd\fR(1M), \fBprintf\fR(3UCB),
\fBsyslog.conf\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)
|