1 .\" $NetBSD: syslog.3,v 1.25 2008/10/31 16:12:18 christos Exp $
2 .\" $OpenBSD: syslog.3,v 1.25 2005/07/22 03:16:58 jaredy Exp $
4 .\" Copyright (c) 1985, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)syslog.3 8.1 (Berkeley) 6/4/93
51 .Nd control system log
57 .Fn syslog "int priority" "const char *message" "..."
59 .Fn syslog_r "int priority" "struct syslog_data *data" "const char *message" "..."
61 .Fn syslogp "int priority" "const char *msgid" "const char *sdfmt" "const char *message" "..."
63 .Fn syslogp_r "int priority" "struct syslog_data *data" "const char *msgid" "const char *sdfmt" "const char *message" "..."
65 .\" .Fn syslog_ss "int priority" "struct syslog_data *data" "const char *message" "..."
67 .Fn openlog "const char *ident" "int logopt" "int facility"
69 .Fn openlog_r "const char *ident" "int logopt" "int facility" "struct syslog_data *data"
73 .Fn closelog_r "struct syslog_data *data"
75 .Fn setlogmask "int maskpri"
77 .Fn setlogmask_r "int maskpri" "struct syslog_data *data"
80 .Fn vsyslog "int priority" "const char *message" "va_list args"
82 .Fn vsyslog_r "int priority" "struct syslog_data *data" "const char *message" "va_list args"
84 .Fn vsyslogp "int priority" "const char *msgid" "const char *sdfmt" "const char *message" "va_list args"
86 .Fn vsyslogp_r "int priority" "struct syslog_data *data" "const char *msgid" "const char *sdfmt" "const char *message" "va_list args"
88 .\" .Fn vsyslog_ss "int priority" "struct syslog_data *data" "const char *message" "va_list args"
101 #define SYSLOG_DATA_INIT { \e
103 .log_fac = LOG_USER, \e
113 to the system message logger.
114 The message is then written to the system console, log files,
115 logged-in users, or forwarded to other machines as appropriate (See
118 The message is identical to a
120 format string, except that
122 is replaced by the current error
124 (As denoted by the global variable
128 A trailing newline is added if none is present.
129 .\" shouldn't the newline statement be removed?
130 .\" when logging through a socket a newline is
131 .\" not added nor is it required. -- ms
134 function is a multithread-safe version of the
137 It takes a pointer to a
139 structure which is used to store
141 This parameter must be initialized before
146 constant is used for this purpose.
149 structure is composed of the following elements:
150 .Bl -tag -width connected
152 contains the file descriptor of the file where the message is logged
154 indicates if connect has been done
163 string to tag the entry with
167 mask of priorities to be logged
172 .\" is the async-signal-safe version of
174 .\" and is also multithread-safe.
175 .\" It has the following limitations:
176 .\" .Bl -enum -offset indent
178 .\" The format string cannot contain multi-byte character sequences.
180 .\" Floating point formats are not supported and print
183 .\" The time of the event is not sent to
186 .\" The error string in the %m format is not printed symbolically but as
190 .\" For more information about async-signal-safe functions and signal handlers, see
196 is an alternative form in which the arguments have already been captured
197 using the variable-length argument facilities of
202 variants take additional arguments which correspond to new fields in the
203 syslog-protocol message format.
204 All three arguments are evaluated as
206 format strings and any of them can be
208 This enables applications to use message IDs, structured data, and UTF-8 encoded
211 The message is tagged with
213 Priorities are encoded as a
217 The facility describes the part of the system
218 generating the message.
219 The level is selected from the following
222 .Bl -tag -width LOG_AUTHPRIV
225 This is normally broadcast to all users.
227 A condition that should be corrected immediately, such as a corrupted
230 Critical conditions, e.g., hard device errors.
236 Conditions that are not error conditions,
237 but should possibly be handled specially.
239 Informational messages.
241 Messages that contain information
242 normally of use only when debugging a program.
247 is used the same way as
249 except that it takes an additional pointer to a
252 It is a multithread-safe version of the
254 function described above.
257 .\" is the async-signal-safe version of
259 .\" is also multithread-safe, and has the same limitations as
265 provides for more specialized processing of the messages sent
272 is a string that will be prepended to every message.
276 is a bit field specifying logging options, which is formed by
278 one or more of the following values:
279 .Bl -tag -width LOG_AUTHPRIV
283 cannot pass the message to
285 it will attempt to write the message to the console
286 .Pq Dq Pa /dev/console .
288 Open the connection to
291 Normally the open is delayed until the first message is logged.
292 Useful for programs that need to manage the order in which file
293 descriptors are allocated.
295 Write the message to standard error output as well to the system log.
297 Log the process id with each message: useful for identifying
298 instantiations of daemons.
299 (This PID is placed within brackets
300 between the ident and the message.)
305 parameter encodes a default facility to be assigned to all messages
306 that do not have an explicit facility encoded:
307 .Bl -tag -width LOG_AUTHPRIV
309 The authorization system:
317 but logged to a file readable only by
318 selected individuals.
323 System daemons, such as
325 that are not provided for explicitly by other facilities.
327 The file transfer protocol daemon:
330 Messages generated by the kernel.
331 These cannot be generated by any user processes.
333 The line printer spooling system:
341 The network news system.
343 Messages generated internally by
346 Messages generated by random user processes.
347 This is the default facility identifier if none is specified.
351 Reserved for local use.
360 function is the multithread-safe version of the
363 It takes an additional pointer to a
366 This function must be used in conjunction with the other
367 multithread-safe functions.
372 can be used to close the log file.
376 does the same thing as
378 but in a multithread-safe way and takes an additional
386 sets the log priority mask to
388 and returns the previous mask.
391 with a priority not set in
394 The mask for an individual priority
396 is calculated by the macro
398 the mask for all priorities up to and including
400 is given by the macro
401 .Fn LOG_UPTO toppri .
402 The default allows all priorities to be logged.
406 function is the multithread-safe version of
408 It takes an additional pointer to a
432 always return the previous log mask level.
434 .Bd -literal -offset indent -compact
435 syslog(LOG_ALERT, "who: internal error 23");
437 openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
439 setlogmask(LOG_UPTO(LOG_ERR));
441 syslog(LOG_INFO, "Connection from host %d", CallingHost);
443 syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
445 syslogp(LOG_INFO|LOG_LOCAL2, NULL, NULL, "foobar error: %m");
447 syslogp(LOG_INFO, "ID%d", "[meta language=\\"en-US\\"]",
448 "event: %s", 42, EventDescription);
451 For the multithread-safe functions:
452 .Bd -literal -offset indent
453 struct syslog_data sdata = SYSLOG_DATA_INIT;
455 syslog_r(LOG_INFO|LOG_LOCAL2, \*[Am]sdata, "foobar error: %m");
464 .%T The BSD syslog Protocol
468 .%N draft-ietf-syslog-protocol-23
470 .%T The syslog Protocol
473 These non-multithread-safe functions appeared in
475 The multithread-safe functions appeared in
479 The async-signal-safe functions appeared in
481 The syslog-protocol functions appeared in
484 It is important never to pass a string with user-supplied data as a
487 An attacker can put format specifiers in the string to mangle your stack,
488 leading to a possible security hole.
489 This holds true even if you have built the string
491 using a function like
493 as the resulting string may still contain user-supplied conversion specifiers
494 for later interpolation by
497 Always be sure to use the proper secure idiom:
498 .Bd -literal -offset indent
499 syslog(priority, "%s", string);
504 the caller is responsible to use the right formatting for the message fields.
507 must only contain up to 32 ASCII characters.
510 has strict rules for paranthesis and character quoting.
513 contains UTF-8 characters, then it has to start with a Byte Order Mark.