Standard C Library Functions syslog(3C)
NAME
syslog, openlog, closelog, setlogmask - control system log
SYNOPSIS
#include
void openlog(const char *ident, int logopt, int facility);
void syslog(int priority, const char *message, .../* arguments */);
void closelog(void);
int setlogmask(int maskpri);
DESCRIPTION
The syslog() function sends a message to syslogd(1M), which,
depending on the configuration of /etc/syslog.conf, logs it
in an appropriate system log, writes it to the system con-
sole, forwards it to a list of users, or forwards it to sys-
logd on another host over the network. The logged message
includes a message header and a message body. The message
header consists of a facility indicator, a severity level
indicator, a timestamp, a tag string, and optionally the
process ID.
The message body is generated from the message and following
arguments in the same manner as if these were arguments to
printf(3UCB), except that occurrences of %m in the format
string pointed to by the message argument are replaced by
the error message string associated with the current value
of errno. A trailing NEWLINE character is added if needed.
Symbolic constants for use as values of the logopt, facil-
ity, priority, and maskpri arguments are defined in the
header.
Values of the priority argument are formed by ORing together
a severity level value and an optional facility value. If
no facility value is specified, the current default facility
value is used.
Possible values of severity level include, in decreasing
order:
SunOS 5.11 Last change: 16 Mar 2009 1
Standard C Library Functions syslog(3C)
LOGEMERG A panic condition. This is normally broad-
cast to all users.
LOGALERT A condition that should be corrected immedi-
ately, such as a corrupted system database.
LOGCRIT Critical conditions, such as hard device
errors.
LOGER Errors.
LOGWARNING Warning messages.
LOGNOTICE Conditions that are not error conditions, but
that may require special handling.
LOGINFO Informational messages.
LOGDEBUG Messages that contain information normally of
use only when debugging a program.
The facility indicates the application or system component
generating the message. Possible facility values include:
LOGKERN Messages generated by the kernel. These cannot
be generated by any user processes.
LOGUSER Messages generated by random user processes.
This is the default facility identifier if
none is specified.
LOGMAIL The mail system.
LOGDAEMON System daemons, such as in.ftpd(1M).
LOGAUTH The authentication / security / authorization
system: login(1), su(1M), getty(1M).
SunOS 5.11 Last change: 16 Mar 2009 2
Standard C Library Functions syslog(3C)
LOGLPR The line printer spooling system: lpr(1B),
lpc(1B).
LOGNEWS Designated for the USENET network news system.
LOGUCP Designated for the UCP system; it does not
currently use syslog().
LOGCRON The cron/at facility; crontab(1), at(1),
cron(1M).
LOGAUDIT The audit facility, for example, auditd(1M).
LOGLOCAL0 Designated for local use.
LOGLOCAL1 Designated for local use.
LOGLOCAL2 Designated for local use.
LOGLOCAL3 Designated for local use.
LOGLOCAL4 Designated for local use.
LOGLOCAL5 Designated for local use.
LOGLOCAL6 Designated for local use.
LOGLOCAL7 Designated for local use.
The openlog() function sets process attributes that affect
subsequent calls to syslog(). The ident argument is a string
that is prepended to every message. The openlog() function
uses the passed-in ident argument directly, rather than mak-
ing a private copy of it. The logopt argument indicates log-
ging options. Values for logopt are constructed by a
bitwise-inclusive OR of zero or more of the following:
SunOS 5.11 Last change: 16 Mar 2009 3
Standard C Library Functions syslog(3C)
LOGPID Log the process ID with each message. This is
useful for identifying specific daemon
processes (for daemons that fork).
LOGCONS Write messages to the system console if they
cannot be sent to syslogd(1M). This option is
safe to use in daemon processes that have no
controlling terminal, since syslog() forks
before opening the console.
LOGNDELAY Open the connection to syslogd(1M) immedi-
ately. 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.
LOGODELAY Delay open until syslog() is called.
LOGNOWAIT 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.
The facility argument encodes a default facility to be
assigned to all messages that do not have an explicit facil-
ity already encoded. The initial default facility is
LOGUSER.
The openlog() and syslog() functions may allocate a file
descriptor. It is not necessary to call openlog() prior to
calling syslog().
The closelog() function closes any open file descriptors
allocated by previous calls to openlog() or syslog().
The setlogmask() function sets the log priority mask for the
current process to maskpri and returns the previous mask.
If the maskpri argument is 0, the current log mask is not
modified. Calls by the current process to syslog() with a
priority not set in maskpri are rejected. The mask for an
SunOS 5.11 Last change: 16 Mar 2009 4
Standard C Library Functions syslog(3C)
individual priority pri is calculated by the macro
LOGMASK(pri); the mask for all priorities up to and includ-
ing toppri is given by the macro LOGUPTO(toppri). The
default log mask allows all priorities to be logged.
RETURN VALUES
The setlogmask() function returns the previous log priority
mask. The closelog(), openlog() and syslog() functions
return no value.
ERORS
No errors are defined.
EXAMPLES
Example 1 Example of LOGALERT message.
This call logs a message at priority LOGALERT:
syslog(LOGALERT, "who: internal error 23");
The FTP daemon ftpd would make this call to openlog() to
indicate that all messages it logs should have an identify-
ing string of ftpd, should be treated by syslogd(1M) as
other messages from system daemons are, should include the
process ID of the process logging the message:
openlog("ftpd", LOGPID, LOGDAEMON);
Then it would make the following call to setlogmask() to
indicate that messages at priorities from LOGEMERG through
LOGER should be logged, but that no messages at any other
priority should be logged:
setlogmask(LOGUPTO(LOGER));
Then, to log a message at priority LOGINFO, it would make
the following call to syslog:
SunOS 5.11 Last change: 16 Mar 2009 5
Standard C Library Functions syslog(3C)
syslog(LOGINFO, "Connection from host %d", CallingHost);
A locally-written utility could use the following call to
syslog() to log a message at priority LOGINFO to be treated
by syslogd(1M) as other messages to the facility LOGLOCAL2
are:
syslog(LOGINFOLOGLOCAL2, "error: %m");
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
Interface Stability Committed
MT-Level Safe
Standard See standards(5).
SEE ALSO
at(1), crontab(1), logger(1), login(1), lpc(1B), lpr(1B),
auditd(1M), cron(1M), getty(1M), in.ftpd(1M), su(1M),
syslogd(1M), printf(3UCB), syslog.conf(4), attributes(5),
standards(5)
SunOS 5.11 Last change: 16 Mar 2009 6
|