9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / syslog.3c
blob6bfe07190c59457216c54d615593fe9ad222ef51
1 .\"
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/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
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.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The Berkeley software License Agreement specifies the terms and conditions
28 .\" for redistribution.
29 .\"
30 .\"
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.
35 .\"
36 .TH SYSLOG 3C "May 13, 2017"
37 .SH NAME
38 syslog, openlog, closelog, setlogmask \- control system log
39 .SH SYNOPSIS
40 .LP
41 .nf
42 #include <syslog.h>
44 \fBvoid\fR \fBopenlog\fR(\fBconst char *\fR\fIident\fR, \fBint\fR \fIlogopt\fR, \fBint\fR \fIfacility\fR);
45 .fi
47 .LP
48 .nf
49 \fBvoid\fR \fBsyslog\fR(\fBint\fR \fIpriority\fR, \fBconst char *\fR\fImessage\fR, \fB\&.../*\fR \fIarguments\fR */);
50 .fi
52 .LP
53 .nf
54 \fBvoid\fR \fBcloselog\fR(\fBvoid\fR);
55 .fi
57 .LP
58 .nf
59 \fBint\fR \fBsetlogmask\fR(\fBint\fR \fImaskpri\fR);
60 .fi
62 .SH DESCRIPTION
63 .LP
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.
71 .sp
72 .LP
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.
78 .sp
79 .LP
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>
82 header.
83 .sp
84 .LP
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.
88 .sp
89 .LP
90 Possible values of severity level include, in decreasing order:
91 .sp
92 .ne 2
93 .na
94 \fB\fBLOG_EMERG\fR\fR
95 .ad
96 .RS 15n
97 A panic condition.  This is normally broadcast to all users.
98 .RE
101 .ne 2
103 \fB\fBLOG_ALERT\fR\fR
105 .RS 15n
106 A condition that should be corrected immediately, such as a corrupted system
107 database.
111 .ne 2
113 \fB\fBLOG_CRIT\fR\fR
115 .RS 15n
116 Critical conditions, such as hard device errors.
120 .ne 2
122 \fB\fBLOG_ERR\fR\fR
124 .RS 15n
125 Errors.
129 .ne 2
131 \fB\fBLOG_WARNING\fR\fR
133 .RS 15n
134 Warning messages.
138 .ne 2
140 \fB\fBLOG_NOTICE\fR\fR
142 .RS 15n
143 Conditions that are not error conditions, but that may require special
144 handling.
148 .ne 2
150 \fB\fBLOG_INFO\fR\fR
152 .RS 15n
153 Informational messages.
157 .ne 2
159 \fB\fBLOG_DEBUG\fR\fR
161 .RS 15n
162 Messages that contain information normally of use only when debugging a
163 program.
168 The facility indicates the application or system component generating the
169 message.  Possible facility values include:
171 .ne 2
173 \fB\fBLOG_KERN\fR\fR
175 .RS 14n
176 Messages generated by the kernel. These cannot be generated by any user
177 processes.
181 .ne 2
183 \fB\fBLOG_USER\fR\fR
185 .RS 14n
186 Messages generated by random user processes. This is the default facility
187 identifier if none is specified.
191 .ne 2
193 \fB\fBLOG_MAIL\fR\fR
195 .RS 14n
196 The mail system.
200 .ne 2
202 \fB\fBLOG_DAEMON\fR\fR
204 .RS 14n
205 System daemons.
209 .ne 2
211 \fB\fBLOG_AUTH\fR\fR
213 .RS 14n
214 The authentication / security / authorization system: \fBlogin\fR(1),
215 \fBsu\fR(1M), \fBgetty\fR(1M).
219 .ne 2
221 \fB\fBLOG_LPR\fR\fR
223 .RS 14n
224 The line printer spooling system: \fBlpr\fR(1B), \fBlpc\fR(1B).
228 .ne 2
230 \fB\fBLOG_NEWS\fR\fR
232 .RS 14n
233 Designated for the \fBUSENET\fR network news system.
237 .ne 2
239 \fB\fBLOG_UUCP\fR\fR
241 .RS 14n
242 Designated for the \fBUUCP\fR system; it does not currently use \fBsyslog()\fR.
246 .ne 2
248 \fB\fBLOG_CRON\fR\fR
250 .RS 14n
251 The \fBcron\fR/\fBat\fR facility; \fBcrontab\fR(1), \fBat\fR(1),
252 \fBcron\fR(1M).
256 .ne 2
258 \fB\fBLOG_AUDIT\fR\fR
260 .RS 14n
261 The audit facility, for example, \fBauditd\fR(1M).
265 .ne 2
267 \fB\fBLOG_LOCAL0\fR\fR
269 .RS 14n
270 Designated for local use.
274 .ne 2
276 \fB\fBLOG_LOCAL1\fR\fR
278 .RS 14n
279 Designated for local use.
283 .ne 2
285 \fB\fBLOG_LOCAL2\fR\fR
287 .RS 14n
288 Designated for local use.
292 .ne 2
294 \fB\fBLOG_LOCAL3\fR\fR
296 .RS 14n
297 Designated for local use.
301 .ne 2
303 \fB\fBLOG_LOCAL4\fR\fR
305 .RS 14n
306 Designated for local use.
310 .ne 2
312 \fB\fBLOG_LOCAL5\fR\fR
314 .RS 14n
315 Designated for local use.
319 .ne 2
321 \fB\fBLOG_LOCAL6\fR\fR
323 .RS 14n
324 Designated for local use.
328 .ne 2
330 \fB\fBLOG_LOCAL7\fR\fR
332 .RS 14n
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:
345 .ne 2
347 \fB\fBLOG_PID\fR\fR
349 .RS 14n
350 Log the process \fBID\fR with each message.  This is useful for identifying
351 specific daemon processes (for daemons that fork).
355 .ne 2
357 \fB\fBLOG_CONS\fR\fR
359 .RS 14n
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.
366 .ne 2
368 \fB\fBLOG_NDELAY\fR\fR
370 .RS 14n
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.
377 .ne 2
379 \fB\fBLOG_ODELAY\fR\fR
381 .RS 14n
382 Delay open until \fBsyslog()\fR is called.
386 .ne 2
388 \fB\fBLOG_NOWAIT\fR\fR
390 .RS 14n
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
406 \fBsyslog()\fR.
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.
421 .SH RETURN VALUES
423 The \fBsetlogmask()\fR function returns the previous log priority mask. The
424 \fBcloselog()\fR, \fBopenlog()\fR and \fBsyslog()\fR functions return no value.
425 .SH ERRORS
427 No errors are defined.
428 .SH EXAMPLES
430 \fBExample 1 \fRExample of \fBLOG_ALERT\fR message.
433 This call logs a message at priority \fBLOG_ALERT\fR:
436 .in +2
438 \fBsyslog(LOG_ALERT, "who: internal error 23")\fR;
440 .in -2
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
449 the message:
452 .in +2
454 \fBopenlog("ftpd", LOG_PID, LOG_DAEMON)\fR;
456 .in -2
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:
466 .in +2
468 \fBsetlogmask(LOG_UPTO(LOG_ERR))\fR;
470 .in -2
475 Then, to log a message at priority \fBLOG_INFO\fR, it would make the following
476 call to \fBsyslog\fR:
479 .in +2
481 \fBsyslog(LOG_INFO, "Connection from host %d", CallingHost)\fR;
483 .in -2
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:
493 .in +2
495 \fBsyslog(LOG_INFO|LOG_LOCAL2, "error: %m")\fR;
497 .in -2
500 .SH ATTRIBUTES
502 See \fBattributes\fR(5) for descriptions of the following attributes:
507 box;
508 c | c
509 l | l .
510 ATTRIBUTE TYPE  ATTRIBUTE VALUE
512 Interface Stability     Committed
514 MT-Level        Safe
516 Standard        See \fBstandards\fR(5).
519 .SH SEE ALSO
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)