xref: /netbsd-src/lib/libc/gen/syslog.3 (revision 1f2744e6e4915c9da2a3f980279398c4cf7d5e6d)
1.\"	$NetBSD: syslog.3,v 1.3 1995/02/27 05:52:39 cgd 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 clock daemon.
179.It Dv LOG_DAEMON
180System daemons, such as
181.Xr routed 8 ,
182that are not provided for explicitly by other facilities.
183.It Dv LOG_KERN
184Messages generated by the kernel.
185These cannot be generated by any user processes.
186.It Dv LOG_LPR
187The line printer spooling system:
188.Xr lpr 1 ,
189.Xr lpc 8 ,
190.Xr lpd 8 ,
191etc.
192.It Dv LOG_MAIL
193The mail system.
194.It Dv LOG_NEWS
195The network news system.
196.It Dv LOG_SYSLOG
197Messages generated internally by
198.Xr syslogd 8 .
199.It Dv LOG_USER
200Messages generated by random user processes.
201This is the default facility identifier if none is specified.
202.It Dv LOG_UUCP
203The uucp system.
204.It Dv LOG_LOCAL0
205Reserved for local use.
206Similarly for
207.Dv LOG_LOCAL1
208through
209.Dv LOG_LOCAL7 .
210.El
211.Pp
212The
213.Fn closelog
214function
215can be used to close the log file.
216.Pp
217The
218.Fn setlogmask
219function
220sets the log priority mask to
221.Fa maskpri
222and returns the previous mask.
223Calls to
224.Fn syslog
225with a priority not set in
226.Fa maskpri
227are rejected.
228The mask for an individual priority
229.Fa pri
230is calculated by the macro
231.Fn LOG_MASK pri ;
232the mask for all priorities up to and including
233.Fa toppri
234is given by the macro
235.Fn LOG_UPTO toppri ; .
236The default allows all priorities to be logged.
237.Sh RETURN VALUES
238The routines
239.Fn closelog ,
240.Fn openlog ,
241.Fn syslog
242and
243.Fn vsyslog
244return no value.
245.Pp
246The routine
247.Fn setlogmask
248always returns the previous log mask level.
249.Sh EXAMPLES
250.Bd -literal -offset indent -compact
251syslog(LOG_ALERT, "who: internal error 23");
252
253openlog("ftpd", LOG_PID, LOG_DAEMON);
254setlogmask(LOG_UPTO(LOG_ERR));
255syslog(LOG_INFO, "Connection from host %d", CallingHost);
256
257syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
258.Ed
259.Sh SEE ALSO
260.Xr logger 1 ,
261.Xr syslogd 8
262.Sh HISTORY
263These
264functions appeared in
265.Bx 4.2 .
266