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