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