syslog, openlog, closelog, setlogmask
Purpose
Makes a system log entry.
Library
Berkeley Library (libbsd.a)
Syntax
#include <bsd/sys/syslog.h>
void syslog (priority, message [, val, ...void closelog ( )
int priority;
char *message; int setlogmask (maskpri)
int maskpri;
void openlog (ident, logopt, facility)
char *ident;
int logopt, facility;
Description
The syslog subroutine writes messages onto the system log
maintained by the syslogd. The message string is similar
to the printf fmt string, with the difference that" %m"
is replaced by the current error message obtained from
errno. A trailing new line can be added to the message
if needed. The val parameters are the same as the val
parameters of the printf subroutine.
Messages are read by the syslogd and written to the
system console or log file, or forwarded to the syslogd
on the appropriate host.
Messages are tagged with codes indicating the type of
priority for each. A priority is encoded as a facility,
which describes the part of the system generating the
message, and as a level, which indicates the severity of
the message.
The facility that generated the message is one of the
following:
LOG_KERN Messages generated by the kernel. These
cannot be generated by any user processes.
LOG_USER Messages generated by user processes. This
is the default facility when none is speci-
fied.
LOG_MAIL The mail system.
LOG_DAEMON System daemons.
LOG_AUTH The authorization system: login, su, and so
on.
LOG_LPR The line printer spooling system.
LOG_LOCAL0 Reserved for local use.
through
LOG_LOCAL7
The level of severity is selected from the following
list:
LOG_EMERG A panic condition reported to all users.
LOG_ALERT A condition that should be corrected imme-
diately; for example, a corrupted database.
LOG_CRIT Critical conditions: for example, hard
device errors.
LOG_ERR Errors.
LOG_WARNING Warning messages.
LOG_NOTICE Not an error condition, but a condition
requiring special handling.
LOG_INFO General information messages.
LOG_DEBUG Messages containing information useful to
debug a program.
If syslog cannot pass the message to syslogd, it writes
the message on /dev/console, provided the LOG_CONS option
is set.
Note: Since AIX does not create file names for AF_UNIX
sockets, there is no /dev/log file created when the
syslogd is started. A program therefore has no way to
find out if the syslogd is running, unless it checks the
process ID contained in /etc/syslog.pid.
If special processing is required, the openlog subroutine
can be used to initialize the log file. The ident param-
eter contains a string that is attached to the beginning
of every message. The facility parameter encodes a
default facility from the previous list to be assigned to
messages that do not have an explicit facility encoded.
The logopt parameter is a bit field that indicates
logging options. The values of logopt include:
LOG_PID Log the process ID with each message. This
option is useful for identifying daemons.
LOG_CONS Send messages to the console if unable to
send them to syslogd. This option is useful
in daemon processes that have no controlling
terminal.
LOG_NDELAY Open the connection to syslogd immediately,
instead of when the first message is logged.
This option is useful for programs that need
to manage the order in which file descrip-
tors are allocated.
LOG_NOWAIT Log messages to the console without waiting
for forked children. Use this option for
processes that enable notification of child
termination through SIGCHLD; otherwise,
syslog may block, waiting for a child whose
exit status has already been collected.
The closelog subroutine closes the log file.
The setlogmask subroutine uses the bit mask in maskpri to
set the new log priority mask and returns the previous
mask. Logging is enabled for the levels indicated by the
bits in the mask that are set and disabled where the bits
are not set. The default mask allows all priorities to
be logged.
The LOG_MASK and LOG_UPTO macros in the bsd/sys/syslog.h
file are used to create the priority mask. Calls to
syslog with a priority mask that does not allow logging
of that particular level of message, cause the subroutine
to return without logging the message.
Examples
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");
Related Information
In this book: "printf, fprintf, sprintf, NLprintf,
NLfprintf, NLsprintf."
The discussion of syslogd in AIX Operating System Com-
mands Reference.