xref: /netbsd-src/lib/libc/gen/syslog.3 (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1.\"	$NetBSD: syslog.3,v 1.5 1995/08/12 05:02:46 jtc Exp $
2.\"
3.\" Copyright (c) 1985, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)syslog.3	8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt SYSLOG 3
38.Os BSD 4.2
39.Sh NAME
40.Nm syslog ,
41.Nm vsyslog ,
42.Nm openlog ,
43.Nm closelog ,
44.Nm setlogmask
45.Nd control system log
46.Sh SYNOPSIS
47.Fd #include <syslog.h>
48.Fd #include <varargs.h>
49.Ft void
50.Fn syslog "int priority" "const char *message" "..."
51.Ft void
52.Fn vsyslog "int priority" "const char *message" "va_list args"
53.Ft void
54.Fn openlog "const char *ident" "int logopt" "int facility"
55.Ft void
56.Fn closelog void
57.Ft int
58.Fn setlogmask "int maskpri"
59.Sh DESCRIPTION
60The
61.Fn syslog
62function
63writes
64.Fa message
65to the system message logger.
66The message is then written to the system console, log files,
67logged-in users, or forwarded to other machines as appropriate. (See
68.Xr syslogd 8 . )
69.Pp
70The message is identical to a
71.Xr printf 3
72format string, except that
73.Ql %m
74is replaced by the current error
75message. (As denoted by the global variable
76.Va errno ;
77see
78.Xr strerror 3 . )
79A trailing newline is added if none is present.
80.Pp
81The
82.Fn vsyslog
83function
84is an alternate form in which the arguments have already been captured
85using the variable-length argument facilities of
86.Xr varargs 3 .
87.Pp
88The message is tagged with
89.Fa priority .
90Priorities are encoded as a
91.Fa facility
92and a
93.Em level .
94The facility describes the part of the system
95generating the message.
96The level is selected from the following
97.Em ordered
98(high to low) list:
99.Bl -tag -width LOG_AUTHPRIV
100.It Dv LOG_EMERG
101A panic condition.
102This is normally broadcast to all users.
103.It Dv LOG_ALERT
104A condition that should be corrected immediately, such as a corrupted
105system database.
106.It Dv LOG_CRIT
107Critical conditions, e.g., hard device errors.
108.It Dv LOG_ERR
109Errors.
110.It Dv LOG_WARNING
111Warning messages.
112.It Dv LOG_NOTICE
113Conditions that are not error conditions,
114but should possibly be handled specially.
115.It Dv LOG_INFO
116Informational messages.
117.It Dv LOG_DEBUG
118Messages that contain information
119normally of use only when debugging a program.
120.El
121.Pp
122The
123.Fn openlog
124function
125provides for more specialized processing of the messages sent
126by
127.Fn syslog
128and
129.Fn vsyslog .
130The parameter
131.Fa ident
132is a string that will be prepended to every message.
133The
134.Fa logopt
135argument
136is a bit field specifying logging options, which is formed by
137.Tn OR Ns 'ing
138one or more of the following values:
139.Bl -tag -width LOG_AUTHPRIV
140.It Dv LOG_CONS
141If
142.Fn syslog
143cannot pass the message to
144.Xr syslogd
145it will attempt to write the message to the console
146.Pq Dq Pa /dev/console.
147.It Dv LOG_NDELAY
148Open the connection to
149.Xr syslogd
150immediately.
151Normally the open is delayed until the first message is logged.
152Useful for programs that need to manage the order in which file
153descriptors are allocated.
154.It Dv LOG_PERROR
155Write the message to standard error output as well to the system log.
156.It Dv LOG_PID
157Log the process id with each message: useful for identifying
158instantiations of daemons.
159.El
160.Pp
161The
162.Fa facility
163parameter encodes a default facility to be assigned to all messages
164that do not have an explicit facility encoded:
165.Bl -tag -width LOG_AUTHPRIV
166.It Dv LOG_AUTH
167The authorization system:
168.Xr login 1 ,
169.Xr su 1 ,
170.Xr getty 8 ,
171etc.
172.It Dv LOG_AUTHPRIV
173The same as
174.Dv LOG_AUTH ,
175but logged to a file readable only by
176selected individuals.
177.It Dv LOG_CRON
178The cron daemon:
179.Xr cron 8 .
180.It Dv LOG_DAEMON
181System daemons, such as
182.Xr routed 8 ,
183that are not provided for explicitly by other facilities.
184.It Dv LOG_FTP
185The file transfer protocol daemon:
186.Xr ftpd 8 .
187.It Dv LOG_KERN
188Messages generated by the kernel.
189These cannot be generated by any user processes.
190.It Dv LOG_LPR
191The line printer spooling system:
192.Xr lpr 1 ,
193.Xr lpc 8 ,
194.Xr lpd 8 ,
195etc.
196.It Dv LOG_MAIL
197The mail system.
198.It Dv LOG_NEWS
199The network news system.
200.It Dv LOG_SYSLOG
201Messages generated internally by
202.Xr syslogd 8 .
203.It Dv LOG_USER
204Messages generated by random user processes.
205This is the default facility identifier if none is specified.
206.It Dv LOG_UUCP
207The uucp system.
208.It Dv LOG_LOCAL0
209Reserved for local use.
210Similarly for
211.Dv LOG_LOCAL1
212through
213.Dv LOG_LOCAL7 .
214.El
215.Pp
216The
217.Fn closelog
218function
219can be used to close the log file.
220.Pp
221The
222.Fn setlogmask
223function
224sets the log priority mask to
225.Fa maskpri
226and returns the previous mask.
227Calls to
228.Fn syslog
229with a priority not set in
230.Fa maskpri
231are rejected.
232The mask for an individual priority
233.Fa pri
234is calculated by the macro
235.Fn LOG_MASK pri ;
236the mask for all priorities up to and including
237.Fa toppri
238is given by the macro
239.Fn LOG_UPTO toppri ; .
240The default allows all priorities to be logged.
241.Sh RETURN VALUES
242The routines
243.Fn closelog ,
244.Fn openlog ,
245.Fn syslog
246and
247.Fn vsyslog
248return no value.
249.Pp
250The routine
251.Fn setlogmask
252always returns the previous log mask level.
253.Sh EXAMPLES
254.Bd -literal -offset indent -compact
255syslog(LOG_ALERT, "who: internal error 23");
256
257openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
258
259setlogmask(LOG_UPTO(LOG_ERR));
260
261syslog(LOG_INFO, "Connection from host %d", CallingHost);
262
263syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
264.Ed
265.Sh SEE ALSO
266.Xr logger 1 ,
267.Xr syslogd 8
268.Sh HISTORY
269These
270functions appeared in
271.Bx 4.2 .
272