update for vnode interface
[unix-history] / usr / src / lib / libc / gen / syslog.3
CommitLineData
5442f39e
KB
1.\" Copyright (c) 1985 The Regents of the University of California.
2.\" All rights reserved.
609b3d57 3.\"
5442f39e
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
c262cc40 16.\" @(#)syslog.3 6.11 (Berkeley) %G%
609b3d57 17.\"
ed6316b8 18.TH SYSLOG 3 ""
609b3d57
KM
19.UC 5
20.SH NAME
38726b8e 21syslog, openlog, closelog, setlogmask, vsyslog \- control system log
609b3d57
KM
22.SH SYNOPSIS
23.B "#include <syslog.h>
24.PP
be78fd26 25.B "openlog(ident, logopt, facility)
609b3d57
KM
26.br
27.B "char *ident;
28.PP
29.B "syslog(priority, message, parameters ... )
30.br
bbb3b705
KB
31.B "int priority;
32.br
33.B "char *message;
34.PP
35.B "#include <varargs.h>
36.br
37.B "vsyslog(priority, message, args)
38.br
39.B "int priority;
40.br
609b3d57 41.B "char *message;
bbb3b705
KB
42.br
43.B "va_list args;
609b3d57
KM
44.PP
45.B "closelog()
ed6316b8
KM
46.PP
47.B "setlogmask(maskpri)
609b3d57
KM
48.SH DESCRIPTION
49.I Syslog
ed6316b8 50arranges to write
609b3d57
KM
51.I message
52onto the system log maintained by
ed6316b8 53.IR syslogd (8).
609b3d57
KM
54The message is tagged with
55.IR priority .
56The message looks like a
57.IR printf (3)
58string except that
59.B %m
60is replaced by the current error message (collected from
61.IR errno ).
bbb3b705
KB
62A trailing newline is added if needed. An alternate form,
63in which the arguments have already been captured using the
64variable-length argument facilities of
65.IR varargs (3),
66is available under the name
67.IR vsyslog .
68.PP
609b3d57 69This message will be read by
ed6316b8
KM
70.IR syslogd (8)
71and written to the system console, log files, or forwarded to
72.I syslogd
73on another host as appropriate.
be78fd26
EA
74.PP
75Priorities are encoded as a
76.I facility
77and a
78.IR level .
79The facility describes the part of the system
80generating the message.
81The level is selected from an ordered list:
c262cc40
KB
82.TP
83LOG_EMERG
be78fd26
EA
84A panic condition.
85This is normally broadcast to all users.
c262cc40
KB
86.TP
87LOG_ALERT
be78fd26
EA
88A condition that should be corrected immediately,
89such as a corrupted system database.
c262cc40
KB
90.TP
91LOG_CRIT
be78fd26
EA
92Critical conditions,
93e.g., hard device errors.
c262cc40
KB
94.TP
95LOG_ERR
be78fd26 96Errors.
c262cc40
KB
97.TP
98LOG_WARNING
be78fd26 99Warning messages.
c262cc40
KB
100.TP
101LOG_NOTICE
be78fd26
EA
102Conditions that are not error conditions,
103but should possibly be handled specially.
c262cc40
KB
104.TP
105LOG_INFO
be78fd26 106Informational messages.
c262cc40
KB
107.TP
108LOG_DEBUG
be78fd26
EA
109Messages that contain information
110normally of use only when debugging a program.
111.PP
ed6316b8
KM
112If
113.I syslog
114cannot pass the message to
6a71ef00
MK
115.IR syslogd ,
116it will attempt to write the message on
117.I /dev/console
118if the LOG_CONS option is set (see below).
609b3d57
KM
119.PP
120If special processing is needed,
121.I openlog
122can be called to initialize the log file.
ed6316b8 123The parameter
609b3d57 124.I ident
ed6316b8
KM
125is a string that is prepended to every message.
126.I Logopt
127is a bit field indicating logging options.
128Current values for
129.I logopt
130are:
c262cc40
KB
131.TP
132LOG_PID
b1d6afbf 133Log the process id with each message:
609b3d57 134useful for identifying instantiations of daemons.
c262cc40
KB
135.TP
136LOG_PERROR
b1d6afbf 137Write the message to stderr as well to the system log.
c262cc40
KB
138.TP
139LOG_CONS
be78fd26 140Force writing messages to the console if unable to send it to
ed6316b8
KM
141.I syslogd.
142This option is safe to use in daemon processes that have no controlling
143terminal since
144.I syslog
145will fork before opening the console.
c262cc40
KB
146.TP
147LOG_NDELAY
6a71ef00 148Open the connection to
ed6316b8 149.I syslogd
0c9a57bf
EA
150immediately.
151Normally the open is delayed
be78fd26
EA
152until the first message is logged.
153Useful for programs that need to manage the
ed6316b8 154order in which file descriptors are allocated.
c262cc40
KB
155.TP
156LOG_NOWAIT
6a71ef00
MK
157Don't wait for children forked to log messages on the console.
158This option should be used by processes that enable notification
159of child termination via SIGCHLD, as
160.I syslog
161may otherwise block waiting for a child whose exit status has already
162been collected.
ed6316b8
KM
163.PP
164The
be78fd26 165.I facility
6a71ef00 166parameter encodes a default facility to be assigned to all messages
be78fd26 167that do not have an explicit facility encoded:
c262cc40
KB
168.TP
169LOG_KERN
be78fd26
EA
170Messages generated by the kernel.
171These cannot be generated by any user processes.
c262cc40
KB
172.TP
173LOG_USER
be78fd26 174Messages generated by random user processes.
6a71ef00 175This is the default facility identifier if none is specified.
c262cc40
KB
176.TP
177LOG_MAIL
be78fd26 178The mail system.
c262cc40
KB
179.TP
180LOG_DAEMON
be78fd26 181System daemons, such as
a7aaa6ab 182.IR ftpd (8),
be78fd26 183.IR routed (8),
c262cc40
KB
184etc, that are not provided for explicitly by other facilities.
185.TP
186LOG_AUTH
be78fd26
EA
187The authorization system:
188.IR login (1),
189.IR su (1),
190.IR getty (8),
191etc.
c262cc40
KB
192.TP
193LOG_SYSLOG
194Messages generated internally by
195.IR syslogd (8).
196.TP
197LOG_LPR
a4e75007
EA
198The line printer spooling system:
199.IR lpr (1),
200.IR lpc (8),
201.IR lpd (8),
202etc.
c262cc40
KB
203.TP
204LOG_NEWS
205The network news system.
206.TP
207LOG_UUCP
208The uucp system.
209.TP
210LOG_CRON
211The clock daemon.
212.TP
213LOG_LOCAL0
be78fd26
EA
214Reserved for local use.
215Similarly for LOG_LOCAL1 through LOG_LOCAL7.
609b3d57
KM
216.PP
217.I Closelog
218can be used to close the log file.
ed6316b8
KM
219.PP
220.I Setlogmask
221sets the log priority mask to
222.I maskpri
223and returns the previous mask.
be78fd26
EA
224Calls to
225.I syslog
6a71ef00 226with a priority not set in
be78fd26
EA
227.I maskpri
228are rejected.
6a71ef00
MK
229The mask for an individual priority
230.I pri
231is calculated by the macro LOG_MASK(\fIpri\fP);
232the mask for all priorities up to and including
233.I toppri
234is given by the macro LOG_UPTO(\fItoppri\fP).
be78fd26 235The default allows all priorities to be logged.
609b3d57
KM
236.SH EXAMPLES
237.nf
be78fd26 238syslog(LOG_ALERT, "who: internal error 23");
609b3d57 239
be78fd26 240openlog("ftpd", LOG_PID, LOG_DAEMON);
6a71ef00 241setlogmask(LOG_UPTO(LOG_ERR));
609b3d57 242syslog(LOG_INFO, "Connection from host %d", CallingHost);
be78fd26
EA
243
244syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
609b3d57 245.fi
ed6316b8 246.SH "SEE ALSO"
be78fd26 247logger(1),
ed6316b8 248syslogd(8)