syslog, openlog, closelog, setlogmask --
control system log
cc [flag . . . ] file . . . -lgen [library] . . .
void openlog(const char ident, int logopt, int facility);
void syslog(int priority, const char message, . . . /* parameters */);
int setlogmask(int maskpri);
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
The message looks like a printf [see
string except that
%m is replaced by the current error message (collected from
is added if needed.
Priorities are encoded as a
The facility describes the part of the system generating the message.
The level is selected from an ordered list:
A panic condition.
This is normally broadcast to all users.
A condition that should be corrected immediately,
such as a corrupted system database.
Critical conditions, such as hard device errors.
Conditions that are not error conditions,
but that may require special handling.
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.
is a string that is prepended to every message.
is a bit field indicating logging options.
Current values for
Log the process
with each message.
This is useful for identifying
specific daemon processes (for daemons that fork).
Write messages to the system console if they cannot be sent to
This option is safe to use in daemon processes that have no controlling
terminal, since syslog forks before opening the console.
Open the connection to syslogd immediately.
Normally the open is delayed until the first message is logged.
This is useful for programs that need to manage the
order in which file descriptors are allocated.
Delay open until syslog() is called.
Do not wait for child processes that have been forked
to log messages onto the console.
This option should be used by processes that enable
notification of child termination using SIGCHLD, since
syslog may otherwise block waiting for a child whose
exit status has already been collected.
parameter encodes a default facility to be assigned to all messages
that do not have an explicit facility already encoded:
Messages generated by the kernel.
These cannot be generated by any user processes.
Messages generated by random user processes.
This is the default facility identifier if none is specified.
The mail system.
System daemons, such as
The authorization system:
Messages generated internally by syslogd.
The line printer spooling system:
Reserved for the USENET network news system.
Reserved for the UUCP system; it does not currently use syslog.
The log alert facility.
The cron/at facility;
Reserved for local use.
closelog can be used to close the log file.
setlogmask sets the log priority mask to
and returns the previous mask.
Calls to syslog with a priority not set in
The mask for an individual priority
is calculated by the macro LOG_MASK
the mask for all priorities up to and including
is given by the macro LOG_UPTO
The default allows all priorities to be logged.
This call logs a message at priority LOG_ALERT:
syslog(LOG_ALERT, "who: internal error 23");
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, and should include the process
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 following 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 treated:
syslog(LOG_INFO|LOG_LOCAL2, "error: %m");
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004