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