HP-UX Reference (11i v2 04/09) - 3 Library Functions N-Z (vol 7)

s
syslog(3C) syslog(3C)
NAME
syslog(), openlog( ), closelog( ), setlogmask( ) - control system log
SYNOPSIS
#include <syslog.h>
void syslog(int priority, const char *message, ...);
void openlog(const char *ident, int logopt, int facility);
void closelog(void);
int setlogmask(int maskpri);
Remarks
The ANSI C ", ..." construct denotes a variable length argument list whose optional [or required]
members are given in the associated comment (
/* */).
DESCRIPTION
syslog() writes a message onto the system log maintained by
syslogd (see syslogd(1M)). The
message is tagged with priority . The message is similar to a printf (3S) format string
except that
%m is replaced by the error message associated with the current value of
errno. A trailing newline is added if needed.
This message is read by
syslogd and written to the system console, log files, selected
users terminals, or forwarded to syslogd on another host as appropriate.
priority is encoded as the logical OR of a level and a facility . The level signifies the
urgency of the message, and facility signifies the subsystem generating the message.
facility can be encoded explicitly in priority , or a default facility can be set with
open-
log() (see below).
level is selected from an ordered list:
LOG_EMERG A panic condition. This is normally broadcast to all users.
LOG_ALERT A condition that should be corrected immediately, such as a
corrupted system database.
LOG_CRIT Critical conditions, such as hard device errors.
LOG_ERR Errors.
LOG_WARNING Warning messages.
LOG_NOTICE Conditions that are not error conditions, but should possibly
be handled specially.
LOG_INFO Informational messages.
LOG_DEBUG Messages that contain information normally of use only when
debugging a program.
syslog() does not log a message that does not have a level set.
If
syslog() cannot pass the message to syslogd, it attempts to write the message on
/dev/console if the LOG_CONS option is set (see below).
openlog() can be called to initialize the log file, if special processing is needed. ident is a string that
precedes every message. logopt is a mask of bits, logically OR’ed together, indicating log-
ging options. The values for logopt are:
LOG_PID Log the process ID with each message; useful for identifying
instantiations of daemons.
LOG_CONS Force writing messages to the console if unable to send it to
syslogd. This option is safe to use in daemon processes that
have no controlling terminal because 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 use-
ful for programs that need to manage the order in which file
HP-UX 11i Version 2: September 2004 1 Hewlett-Packard Company Section 31039