.\" Copyright (c) 1985 The Regents of the University of California. .\" All rights reserved. .\" .\" %sccs.include.redist.man% .\" .\" @(#)syslog.3 6.14 (Berkeley) %G% .\" .TH SYSLOG 3 "" .UC 5 .SH NAME syslog, vsyslog, openlog, closelog, setlogmask \- control system log .SH SYNOPSIS .nf .ft B #include syslog(int priority, char *message, [, arg ] ... ); include vsyslog(int priority, char *message, va_list args); openlog(char *ident, int logopt, int facility); closelog(void); setlogmask(int maskpri); .ft R .fi .SH DESCRIPTION .I Syslog writes .I message to the system message logger. The message will then be written to the system console, log files, logged-in users, or forwarded to other machines as appropriate (see .IR syslogd (8)). .PP The message is identical to a .IR printf (3) format string, except that ``%m'' is replaced by the current error message (as denoted by .IR errno ; see .IR strerror (3)). A trailing newline is added if none is present. .PP .I Vsyslog is an alternate form in which the arguments have already been captured using the variable-length argument facilities of .IR varargs (3). .PP The message is tagged with .IR priority . Priorities are encoded as a .I facility and a .IR level . The facility describes the part of the system generating the message. The level is selected from the following .B ordered (high to low) list: .TP LOG_EMERG A panic condition. This is normally broadcast to all users. .TP LOG_ALERT A condition that should be corrected immediately, such as a corrupted system database. .TP LOG_CRIT Critical conditions, e.g., hard device errors. .TP LOG_ERR Errors. .TP LOG_WARNING Warning messages. .TP LOG_NOTICE Conditions that are not error conditions, but should possibly be handled specially. .TP LOG_INFO Informational messages. .TP LOG_DEBUG Messages that contain information normally of use only when debugging a program. .PP .I Openlog provides for more specialized processing of the messages sent by .I syslog and .IR vsyslog . The parameter .I ident is a string that will be prepended to every message. .I Logopt is a bit field specifying logging options, which is formed by .IR OR 'ing one or more of the following values: .TP LOG_CONS If .I syslog cannot pass the message to .I syslogd it will attempt to write the message to the console (``/dev/console''). .TP LOG_NDELAY Open the connection to .I syslogd immediately. Normally the open is delayed until the first message is logged. Useful for programs that need to manage the order in which file descriptors are allocated. .TP LOG_PERROR Write the message to standard error output as well to the system log. .TP LOG_PID Log the process id with each message: useful for identifying instantiations of daemons. .PP The .I facility parameter encodes a default facility to be assigned to all messages that do not have an explicit facility encoded: .TP LOG_AUTH The authorization system: .IR login (1), .IR su (1), .IR getty (8), etc. .TP LOG_AUTHPRIV The same as LOG_AUTH, but logged to a file readable only by selected individuals. .TP LOG_CRON The clock daemon. .TP LOG_DAEMON System daemons, such as .IR ftpd (8), .IR routed (8), etc., that are not provided for explicitly by other facilities. .TP LOG_KERN Messages generated by the kernel. These cannot be generated by any user processes. .TP LOG_LPR The line printer spooling system: .IR lpr (1), .IR lpc (8), .IR lpd (8), etc. .TP LOG_MAIL The mail system. .TP LOG_NEWS The network news system. .TP LOG_SYSLOG Messages generated internally by .IR syslogd (8). .TP LOG_USER Messages generated by random user processes. This is the default facility identifier if none is specified. .TP LOG_UUCP The uucp system. .TP LOG_LOCAL0 Reserved for local use. Similarly for LOG_LOCAL1 through LOG_LOCAL7. .PP .I Closelog can be used to close the log file. .PP .I Setlogmask sets the log priority mask to .I maskpri and returns the previous mask. Calls to .I syslog with a priority not set in .I maskpri are rejected. The mask for an individual priority .I pri is calculated by the macro ``LOG_MASK(pri);'' the mask for all priorities up to and including .I toppri is given by the macro ``LOG_UPTO(toppri);''. The default allows all priorities to be logged. .SH EXAMPLES .nf .RS syslog(LOG_ALERT, "who: internal error 23"); openlog("ftpd", LOG_PID, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_ERR)); syslog(LOG_INFO, "Connection from host %d", CallingHost); syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); .RE .fi .SH RETURNS The routines .I closelog , .I openlog , .I syslog and .I vsyslog return 0 upon successful completion. Otherwise, -1 is returned and .I errno is set to indicate the error. .PP The routine .I setlogmask always returns the previous log mask level, never returning an error. .SH ERRORS The routines .I syslog and .I vsyslog may fail and set errno for any of the errors specified for the library routines .IR connect (2), .IR send (2) , and .IR socket (2). .PP The routine .I openlog may fail and set errno for any of the errors specified for the library routines .IR connect (2) and .IR socket (2). .PP The routine .I closelog may fail and set errno for any of the errors specified for the library routine .IR close (2). .SH "SEE ALSO" logger(1), syslogd(8)