syslog(), vsyslog(), openlog(), closelog(), setlogmask() - control system log
#include <syslog.h>
#include <stdarg.h>
void syslog (int priority, const char *message, ...)
void vsyslog (int priority, const char *message, va_list args)
void openlog (const char *ident, int logopt, int facility)
void closelog (void)
int setlogmask (int maskpri)
The syslog(3) function writes message to the system message logger. The message is then written to log files, logged-in users, or forwarded to other machines as appropriate. (See syslogd(1).) If the syslogd(1) program is not running, the message is written to the file /var/adm/log/logger.
The message is identical to a printf(3) format string, except that %m is replaced by the current error message (as denoted by the global variable errno; see strerror(3)). A trailing newline is added if none is present.
The vsyslog(3) function is an alternate form in which the arguments have already been captured using the variable-length argument facilities of stdarg(3) (note that it is not varargs, as in many implementations).
The message is tagged with priority. Priorities are encoded as a facility and a level. The facility describes the part of the system generating the message. The level is selected from the following ordered (high to low) list:
The openlog(3) function provides for more specialized processing of the messages sent by syslog(3) and vsyslog(3). The parameter ident is a string that will be prepended to every message. The logopt argument is a bit field specifying logging options, which is formed by ORing one or more of the following values:
The facility parameter encodes a default facility to be assigned to all messages that do not have an explicit facility encoded:
The closelog(3) function can be used to close the log file.
The setlogmask(3) function sets the log priority mask to maskpri and returns the previous mask. Calls to syslog(3) with a priority not set in maskpri are rejected. The mask for an individual priority pri is calculated by the macro LOG_MASK(pri); the mask for all priorities up to and including toppri is given by the macro LOG_UPTO(toppri);. The default allows all priorities to be logged.
The routines closelog(3), openlog(3), syslog(3), and vsyslog(3) return no value.
The routine setlogmask(3) always returns the previous log mask level.
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");
logger(1)
syslogd(1)