2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright (c) 1983 Regents of the University of California. All rights reserved. The Berkeley software License Agreement specifies the terms and conditions for redistribution.
4 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
5 .\" 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/.
6 .\" 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
7 .\" 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
8 .\" 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.
9 .\" This notice shall appear on any product containing this material.
10 .TH SYSLOG 3C "Mar 16, 2009"
12 syslog, openlog, closelog, setlogmask \- control system log
18 \fBvoid\fR \fBopenlog\fR(\fBconst char *\fR\fIident\fR, \fBint\fR \fIlogopt\fR, \fBint\fR \fIfacility\fR);
23 \fBvoid\fR \fBsyslog\fR(\fBint\fR \fIpriority\fR, \fBconst char *\fR\fImessage\fR, \fB\&.../*\fR \fIarguments\fR */);
28 \fBvoid\fR \fBcloselog\fR(\fBvoid\fR);
33 \fBint\fR \fBsetlogmask\fR(\fBint\fR \fImaskpri\fR);
38 The \fBsyslog()\fR function sends a message to \fBsyslogd\fR(1M), which,
39 depending on the configuration of \fB/etc/syslog.conf\fR, logs it in an
40 appropriate system log, writes it to the system console, forwards it to a list
41 of users, or forwards it to \fBsyslogd\fR on another host over the network.
42 The logged message includes a message header and a message body. The message
43 header consists of a facility indicator, a severity level indicator, a
44 timestamp, a tag string, and optionally the process ID.
47 The message body is generated from the \fImessage\fR and following arguments in
48 the same manner as if these were arguments to \fBprintf\fR(3UCB), except that
49 occurrences of \fB%m\fR in the format string pointed to by the \fImessage\fR
50 argument are replaced by the error message string associated with the current
51 value of \fBerrno\fR. A trailing \fBNEWLINE\fR character is added if needed.
54 Symbolic constants for use as values of the \fIlogopt\fR, \fIfacility\fR,
55 \fIpriority\fR, and \fImaskpri\fR arguments are defined in the <\fBsyslog.h\fR>
59 Values of the \fIpriority\fR argument are formed by ORing together a
60 \fIseverity level\fR value and an optional \fIfacility\fR value. If no
61 facility value is specified, the current default facility value is used.
64 Possible values of severity level include, in decreasing order:
71 A panic condition. This is normally broadcast to all users.
80 A condition that should be corrected immediately, such as a corrupted system
90 Critical conditions, such as hard device errors.
105 \fB\fBLOG_WARNING\fR\fR
114 \fB\fBLOG_NOTICE\fR\fR
117 Conditions that are not error conditions, but that may require special
127 Informational messages.
133 \fB\fBLOG_DEBUG\fR\fR
136 Messages that contain information normally of use only when debugging a
142 The facility indicates the application or system component generating the
143 message. Possible facility values include:
150 Messages generated by the kernel. These cannot be generated by any user
160 Messages generated by random user processes. This is the default facility
161 identifier if none is specified.
176 \fB\fBLOG_DAEMON\fR\fR
188 The authentication / security / authorization system: \fBlogin\fR(1),
189 \fBsu\fR(1M), \fBgetty\fR(1M).
198 The line printer spooling system: \fBlpr\fR(1B), \fBlpc\fR(1B).
207 Designated for the \fBUSENET\fR network news system.
216 Designated for the \fBUUCP\fR system; it does not currently use \fBsyslog()\fR.
225 The \fBcron\fR/\fBat\fR facility; \fBcrontab\fR(1), \fBat\fR(1),
232 \fB\fBLOG_AUDIT\fR\fR
235 The audit facility, for example, \fBauditd\fR(1M).
241 \fB\fBLOG_LOCAL0\fR\fR
244 Designated for local use.
250 \fB\fBLOG_LOCAL1\fR\fR
253 Designated for local use.
259 \fB\fBLOG_LOCAL2\fR\fR
262 Designated for local use.
268 \fB\fBLOG_LOCAL3\fR\fR
271 Designated for local use.
277 \fB\fBLOG_LOCAL4\fR\fR
280 Designated for local use.
286 \fB\fBLOG_LOCAL5\fR\fR
289 Designated for local use.
295 \fB\fBLOG_LOCAL6\fR\fR
298 Designated for local use.
304 \fB\fBLOG_LOCAL7\fR\fR
307 Designated for local use.
312 The \fBopenlog()\fR function sets process attributes that affect subsequent
313 calls to \fBsyslog()\fR. The \fIident\fR argument is a string that is prepended
314 to every message. The \fBopenlog()\fR function uses the passed-in \fIident\fR
315 argument directly, rather than making a private copy of it. The \fIlogopt\fR
316 argument indicates logging options. Values for \fIlogopt\fR are constructed by
317 a bitwise-inclusive OR of zero or more of the following:
324 Log the process \fBID\fR with each message. This is useful for identifying
325 specific daemon processes (for daemons that fork).
334 Write messages to the system console if they cannot be sent to
335 \fBsyslogd\fR(1M). This option is safe to use in daemon processes that have no
336 controlling terminal, since \fBsyslog()\fR forks before opening the console.
342 \fB\fBLOG_NDELAY\fR\fR
345 Open the connection to \fBsyslogd\fR(1M) immediately. Normally the open is
346 delayed until the first message is logged. This is useful for programs that
347 need to manage the order in which file descriptors are allocated.
353 \fB\fBLOG_ODELAY\fR\fR
356 Delay open until \fBsyslog()\fR is called.
362 \fB\fBLOG_NOWAIT\fR\fR
365 Do not wait for child processes that have been forked to log messages onto the
366 console. This option should be used by processes that enable notification of
367 child termination using \fBSIGCHLD\fR, since \fBsyslog()\fR may otherwise block
368 waiting for a child whose exit status has already been collected.
373 The \fIfacility\fR argument encodes a default facility to be assigned to all
374 messages that do not have an explicit facility already encoded. The initial
375 default facility is \fBLOG_USER\fR.
378 The \fBopenlog()\fR and \fBsyslog()\fR functions may allocate a file
379 descriptor. It is not necessary to call \fBopenlog()\fR prior to calling
383 The \fBcloselog()\fR function closes any open file descriptors allocated by
384 previous calls to \fBopenlog()\fR or \fBsyslog()\fR.
387 The \fBsetlogmask()\fR function sets the log priority mask for the current
388 process to \fImaskpri\fR and returns the previous mask. If the \fImaskpri\fR
389 argument is 0, the current log mask is not modified. Calls by the current
390 process to \fBsyslog()\fR with a priority not set in \fImaskpri\fR are
391 rejected. The mask for an individual priority \fIpri\fR is calculated by the
392 macro \fBLOG_MASK(\fIpri\fR)\fR; the mask for all priorities up to and
393 including \fItoppri\fR is given by the macro \fBLOG_UPTO(\fItoppri\fR)\fR. The
394 default log mask allows all priorities to be logged.
397 The \fBsetlogmask()\fR function returns the previous log priority mask. The
398 \fBcloselog()\fR, \fBopenlog()\fR and \fBsyslog()\fR functions return no value.
401 No errors are defined.
404 \fBExample 1 \fRExample of \fBLOG_ALERT\fR message.
407 This call logs a message at priority \fBLOG_ALERT\fR:
412 \fBsyslog(LOG_ALERT, "who: internal error 23")\fR;
419 The \fBFTP\fR daemon \fBftpd\fR would make this call to \fBopenlog()\fR to
420 indicate that all messages it logs should have an identifying string of
421 \fBftpd\fR, should be treated by \fBsyslogd\fR(1M) as other messages from
422 system daemons are, should include the process \fBID\fR of the process logging
428 \fBopenlog("ftpd", LOG_PID, LOG_DAEMON)\fR;
435 Then it would make the following call to \fBsetlogmask()\fR to indicate that
436 messages at priorities from \fBLOG_EMERG\fR through \fBLOG_ERR\fR should be
437 logged, but that no messages at any other priority should be logged:
442 \fBsetlogmask(LOG_UPTO(LOG_ERR))\fR;
449 Then, to log a message at priority \fBLOG_INFO\fR, it would make the following
450 call to \fBsyslog\fR:
455 \fBsyslog(LOG_INFO, "Connection from host %d", CallingHost)\fR;
462 A locally-written utility could use the following call to \fBsyslog()\fR to log
463 a message at priority \fBLOG_INFO\fR to be treated by \fBsyslogd\fR(1M) as
464 other messages to the facility \fBLOG_LOCAL2\fR are:
469 \fBsyslog(LOG_INFO|LOG_LOCAL2, "error: %m")\fR;
476 See \fBattributes\fR(5) for descriptions of the following attributes:
484 ATTRIBUTE TYPE ATTRIBUTE VALUE
486 Interface Stability Committed
490 Standard See \fBstandards\fR(5).
495 \fBat\fR(1), \fBcrontab\fR(1), \fBlogger\fR(1), \fBlogin\fR(1), \fBlpc\fR(1B),
496 \fBlpr\fR(1B), \fBauditd\fR(1M), \fBcron\fR(1M), \fBgetty\fR(1M),
497 \fBsu\fR(1M), \fBsyslogd\fR(1M), \fBprintf\fR(3UCB),
498 \fBsyslog.conf\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)