2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The Berkeley software License Agreement specifies the terms and conditions
28 .\" for redistribution.
31 .\" Copyright (c) 1983 Regents of the University of California.
32 .\" All rights reserved.
33 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
34 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
36 .TH SYSLOG 3C "May 13, 2017"
38 syslog, openlog, closelog, setlogmask \- control system log
44 \fBvoid\fR \fBopenlog\fR(\fBconst char *\fR\fIident\fR, \fBint\fR \fIlogopt\fR, \fBint\fR \fIfacility\fR);
49 \fBvoid\fR \fBsyslog\fR(\fBint\fR \fIpriority\fR, \fBconst char *\fR\fImessage\fR, \fB\&.../*\fR \fIarguments\fR */);
54 \fBvoid\fR \fBcloselog\fR(\fBvoid\fR);
59 \fBint\fR \fBsetlogmask\fR(\fBint\fR \fImaskpri\fR);
64 The \fBsyslog()\fR function sends a message to \fBsyslogd\fR(1M), which,
65 depending on the configuration of \fB/etc/syslog.conf\fR, logs it in an
66 appropriate system log, writes it to the system console, forwards it to a list
67 of users, or forwards it to \fBsyslogd\fR on another host over the network.
68 The logged message includes a message header and a message body. The message
69 header consists of a facility indicator, a severity level indicator, a
70 timestamp, a tag string, and optionally the process ID.
73 The message body is generated from the \fImessage\fR and following arguments in
74 the same manner as if these were arguments to \fBprintf\fR(3C), except that
75 occurrences of \fB%m\fR in the format string pointed to by the \fImessage\fR
76 argument are replaced by the error message string associated with the current
77 value of \fBerrno\fR. A trailing \fBNEWLINE\fR character is added if needed.
80 Symbolic constants for use as values of the \fIlogopt\fR, \fIfacility\fR,
81 \fIpriority\fR, and \fImaskpri\fR arguments are defined in the <\fBsyslog.h\fR>
85 Values of the \fIpriority\fR argument are formed by ORing together a
86 \fIseverity level\fR value and an optional \fIfacility\fR value. If no
87 facility value is specified, the current default facility value is used.
90 Possible values of severity level include, in decreasing order:
97 A panic condition. This is normally broadcast to all users.
103 \fB\fBLOG_ALERT\fR\fR
106 A condition that should be corrected immediately, such as a corrupted system
116 Critical conditions, such as hard device errors.
131 \fB\fBLOG_WARNING\fR\fR
140 \fB\fBLOG_NOTICE\fR\fR
143 Conditions that are not error conditions, but that may require special
153 Informational messages.
159 \fB\fBLOG_DEBUG\fR\fR
162 Messages that contain information normally of use only when debugging a
168 The facility indicates the application or system component generating the
169 message. Possible facility values include:
176 Messages generated by the kernel. These cannot be generated by any user
186 Messages generated by random user processes. This is the default facility
187 identifier if none is specified.
202 \fB\fBLOG_DAEMON\fR\fR
214 The authentication / security / authorization system: \fBlogin\fR(1),
215 \fBsu\fR(1M), \fBgetty\fR(1M).
224 The line printer spooling system: \fBlpr\fR(1B), \fBlpc\fR(1B).
233 Designated for the \fBUSENET\fR network news system.
242 Designated for the \fBUUCP\fR system; it does not currently use \fBsyslog()\fR.
251 The \fBcron\fR/\fBat\fR facility; \fBcrontab\fR(1), \fBat\fR(1),
258 \fB\fBLOG_AUDIT\fR\fR
261 The audit facility, for example, \fBauditd\fR(1M).
267 \fB\fBLOG_LOCAL0\fR\fR
270 Designated for local use.
276 \fB\fBLOG_LOCAL1\fR\fR
279 Designated for local use.
285 \fB\fBLOG_LOCAL2\fR\fR
288 Designated for local use.
294 \fB\fBLOG_LOCAL3\fR\fR
297 Designated for local use.
303 \fB\fBLOG_LOCAL4\fR\fR
306 Designated for local use.
312 \fB\fBLOG_LOCAL5\fR\fR
315 Designated for local use.
321 \fB\fBLOG_LOCAL6\fR\fR
324 Designated for local use.
330 \fB\fBLOG_LOCAL7\fR\fR
333 Designated for local use.
338 The \fBopenlog()\fR function sets process attributes that affect subsequent
339 calls to \fBsyslog()\fR. The \fIident\fR argument is a string that is prepended
340 to every message. The \fBopenlog()\fR function uses the passed-in \fIident\fR
341 argument directly, rather than making a private copy of it. The \fIlogopt\fR
342 argument indicates logging options. Values for \fIlogopt\fR are constructed by
343 a bitwise-inclusive OR of zero or more of the following:
350 Log the process \fBID\fR with each message. This is useful for identifying
351 specific daemon processes (for daemons that fork).
360 Write messages to the system console if they cannot be sent to
361 \fBsyslogd\fR(1M). This option is safe to use in daemon processes that have no
362 controlling terminal, since \fBsyslog()\fR forks before opening the console.
368 \fB\fBLOG_NDELAY\fR\fR
371 Open the connection to \fBsyslogd\fR(1M) immediately. Normally the open is
372 delayed until the first message is logged. This is useful for programs that
373 need to manage the order in which file descriptors are allocated.
379 \fB\fBLOG_ODELAY\fR\fR
382 Delay open until \fBsyslog()\fR is called.
388 \fB\fBLOG_NOWAIT\fR\fR
391 Do not wait for child processes that have been forked to log messages onto the
392 console. This option should be used by processes that enable notification of
393 child termination using \fBSIGCHLD\fR, since \fBsyslog()\fR may otherwise block
394 waiting for a child whose exit status has already been collected.
399 The \fIfacility\fR argument encodes a default facility to be assigned to all
400 messages that do not have an explicit facility already encoded. The initial
401 default facility is \fBLOG_USER\fR.
404 The \fBopenlog()\fR and \fBsyslog()\fR functions may allocate a file
405 descriptor. It is not necessary to call \fBopenlog()\fR prior to calling
409 The \fBcloselog()\fR function closes any open file descriptors allocated by
410 previous calls to \fBopenlog()\fR or \fBsyslog()\fR.
413 The \fBsetlogmask()\fR function sets the log priority mask for the current
414 process to \fImaskpri\fR and returns the previous mask. If the \fImaskpri\fR
415 argument is 0, the current log mask is not modified. Calls by the current
416 process to \fBsyslog()\fR with a priority not set in \fImaskpri\fR are
417 rejected. The mask for an individual priority \fIpri\fR is calculated by the
418 macro \fBLOG_MASK(\fIpri\fR)\fR; the mask for all priorities up to and
419 including \fItoppri\fR is given by the macro \fBLOG_UPTO(\fItoppri\fR)\fR. The
420 default log mask allows all priorities to be logged.
423 The \fBsetlogmask()\fR function returns the previous log priority mask. The
424 \fBcloselog()\fR, \fBopenlog()\fR and \fBsyslog()\fR functions return no value.
427 No errors are defined.
430 \fBExample 1 \fRExample of \fBLOG_ALERT\fR message.
433 This call logs a message at priority \fBLOG_ALERT\fR:
438 \fBsyslog(LOG_ALERT, "who: internal error 23")\fR;
445 The \fBFTP\fR daemon \fBftpd\fR would make this call to \fBopenlog()\fR to
446 indicate that all messages it logs should have an identifying string of
447 \fBftpd\fR, should be treated by \fBsyslogd\fR(1M) as other messages from
448 system daemons are, should include the process \fBID\fR of the process logging
454 \fBopenlog("ftpd", LOG_PID, LOG_DAEMON)\fR;
461 Then it would make the following call to \fBsetlogmask()\fR to indicate that
462 messages at priorities from \fBLOG_EMERG\fR through \fBLOG_ERR\fR should be
463 logged, but that no messages at any other priority should be logged:
468 \fBsetlogmask(LOG_UPTO(LOG_ERR))\fR;
475 Then, to log a message at priority \fBLOG_INFO\fR, it would make the following
476 call to \fBsyslog\fR:
481 \fBsyslog(LOG_INFO, "Connection from host %d", CallingHost)\fR;
488 A locally-written utility could use the following call to \fBsyslog()\fR to log
489 a message at priority \fBLOG_INFO\fR to be treated by \fBsyslogd\fR(1M) as
490 other messages to the facility \fBLOG_LOCAL2\fR are:
495 \fBsyslog(LOG_INFO|LOG_LOCAL2, "error: %m")\fR;
502 See \fBattributes\fR(5) for descriptions of the following attributes:
510 ATTRIBUTE TYPE ATTRIBUTE VALUE
512 Interface Stability Committed
516 Standard See \fBstandards\fR(5).
521 \fBat\fR(1), \fBcrontab\fR(1), \fBlogger\fR(1), \fBlogin\fR(1), \fBlpc\fR(1B),
522 \fBlpr\fR(1B), \fBauditd\fR(1M), \fBcron\fR(1M), \fBgetty\fR(1M),
523 \fBsu\fR(1M), \fBsyslogd\fR(1M), \fBprintf\fR(3C),
524 \fBsyslog.conf\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)