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