SYSLOG(3) Library Functions Manual SYSLOG(3)
syslog, openlog, closelog, setlogmask - control system log
openlog(ident, logopt, facility)
syslog(priority, message, parameters ... )
syslog() passes message to syslogd(8), which logs it in an appropriate
system log, writes it to the system console, forwards it to a list of
users, or forwards it to the syslogd on another host over the network.
The message is tagged with a priority of priority. The message looks
like a printf(3V) string except that %m is replaced by the current
error message (collected from errno). A trailing NEWLINE is added if
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 an ordered list:
LOG_EMERG A panic condition. This is normally broad-
cast to all users.
LOG_ALERT A condition that should be corrected immedi-
ately, such as a corrupted system database.
LOG_CRIT Critical conditions, such as hard device
LOG_WARNING Warning messages.
LOG_NOTICE Conditions that are not error conditions,
but that may require special handling.
LOG_INFO Informational messages.
LOG_DEBUG Messages that contain information normally
of use only when debugging a program.
If special processing is needed, openlog() can be called to initialize
the log file. The parameter ident is a string that is prepended to
every message. logopt is a bit field indicating logging options. Cur-
rent values for logopt are:
LOG_PID Log the process ID with each message. This
is useful for identifying specific daemon
processes (for daemons that fork).
LOG_CONS Write messages to the system console if they
cannot be sent to syslogd. This option is
safe to use in daemon processes that have no
controlling terminal, since syslog() forks
before opening the console.
LOG_NDELAY Open the connection to syslogd immediately.
Normally the open is delayed until the first
message is logged. This is useful for pro-
grams that need to manage the order in which
file descriptors are allocated.
LOG_NOWAIT Do not wait for child processes that have
been forked to log messages onto the con-
sole. This option should be used by pro-
cesses that enable notification of child
termination using SIGCHLD, since syslog()
may otherwise block waiting for a child
whose exit status has already been col-
The facility parameter encodes a default facility to be assigned to all
messages that do not have an explicit facility already encoded:
LOG_KERN Messages generated by the kernel. These
cannot be generated by any user processes.
LOG_USER Messages generated by random user processes.
This is the default facility identifier if
none is specified.
LOG_MAIL The mail system.
LOG_DAEMON System daemons, such as ftpd(8C),
LOG_AUTH The authorization system: login(1), su(1V),
LOG_LPR The line printer spooling system: lpr(1),
lpc(8), lpd(8), etc.
LOG_NEWS Reserved for the USENET network news system.
LOG_UUCP Reserved for the UUCP system; it does not
currently use syslog.
LOG_CRON The cron/at facility; crontab(1), at(1),
LOG_LOCAL0-7 Reserved for local use.
closelog() can be used to close the log file.
setlogmask() sets the log priority mask to maskpri and returns the pre-
vious mask. Calls to syslog() 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.
This call logs a message at priority LOG_ALERT:
syslog(LOG_ALERT, "who: internal error 23");
The FTP daemon ftpd would make this call to openlog() to indicate that
all messages it logs should have an identifying string of ftpd, should
be treated by syslogd as other messages from system daemons are, should
include the process ID of the process logging the message:
openlog("ftpd", LOG_PID, LOG_DAEMON);
Then it would make the following call to setlogmask() to indicate that
messages at priorities from LOG_EMERG through LOG_ERR should be logged,
but that no messages at any other priority should be logged:
Then, to log a message at priority LOG_INFO, it would make the follow-
ing call to syslog:
syslog(LOG_INFO, "Connection from host %d", CallingHost);
A locally-written utility could use the following call to syslog() to
log a message at priority LOG_INFO to be treated by syslogd as other
messages to the facility LOG_LOCAL2 are:
syslog(LOG_INFO|LOG_LOCAL2, "error: %m");
at(1), crontab(1), logger(1), login(1), lpr(1), su(1V), printf(3V),
syslog.conf(5), cron(8), ftpd(8C), getty(8), lpc(8), lpd(8),
22 November 1987 SYSLOG(3)