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