'\"macro stdmacro
.if n .pH g3.syslog @(#)syslog	40.8 of 9/21/89
.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved.
.\"
.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved.  The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.nr X
.if \nX=0 .ds x} syslog 3 "BSD Compatibility Package" "\&"
.if \nX=1 .ds x} syslog 3 "BSD Compatibility Package"
.if \nX=2 .ds x} syslog 3 "" "\&"
.if \nX=3 .ds x} syslog "" "" "\&"
.TH \*(x}
.SH NAME
\f4syslog\f1, \f4openlog\f1, \f4closelog\f1, \f4setlogmask\f1 \- control system log
.SH SYNOPSIS
.nf
\f4cc \f1[ \f2flag\f1... ] \f2file\f1 ... \f4\-lucb\f1
.P
\f4#include <syslog.h>\f1
.P
\f4openlog(ident, logopt, facility)\f1
\f4char \(**ident;\f1
.P
\f4syslog(priority, message, parameters \&.\|.\|. )\f1
\f4char \(**message;\f1
.P
\f4closelog()\f1
.P
\f4setlogmask(maskpri)\f1
.fi
.SH DESCRIPTION
.P
\f4syslog\f1
passes
.I message
to
\f4syslogd\f1(1M),
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
\f4syslogd\f1
on another host over the network.
The message is tagged with a priority of
.IR priority .
The message looks like a
\f4printf\f1(3S)
string except that
\f4%m\f1
is replaced by the current error message (collected from
\f4errno\f1).
A trailing
.SM NEWLINE
is added if needed.
.P
Priorities are encoded as a
.I facility
and a
.IR level .
The facility describes the part of the system
generating the message.
The level is selected from an ordered list:
.RS
.TP 20
\f4LOG_EMERG\fP
A panic condition.  This is normally broadcast to all users.
.TP
\f4LOG_ALERT\fP
A condition that should be corrected immediately,
such as a corrupted system database.
.TP
\f4LOG_CRIT\fP
Critical conditions, such as hard device errors.
.TP
\f4LOG_ERR\fP
Errors.
.TP
\f4LOG_WARNING\fP
Warning messages.
.TP
\f4LOG_NOTICE\fP
Conditions that are not error conditions,
but that may require special handling.
.TP
\f4LOG_INFO\fP
Informational messages.
.TP
\f4LOG_DEBUG\fP
Messages that contain information
normally of use only when debugging a program.
.RE
.P
If special processing is needed,
\f4openlog\f1
can be called to initialize the log file.
The parameter
.I ident
is a string that is prepended to every message.
.I logopt
is a bit field indicating logging options.
Current values for
.I logopt
are:
.RS
.TP 20
\f4LOG_PID\fP
Log the process
.SM ID
with each message.  This is useful for identifying
specific daemon processes (for daemons that fork).
.TP
\f4LOG_CONS\fP
Write messages to the system console if they
cannot be sent to
\f4syslogd\f1.
This option is safe to use in daemon processes
that have no controlling terminal, since
\f4syslog\f1
forks before opening the console.
.TP
\f4LOG_NDELAY\fP
Open the connection to
\f4syslogd\f1
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.
.TP
\f4LOG_NOWAIT\fP
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
\f4SIGCHLD\f1,
since
\f4syslog\f1
may otherwise block waiting for a child whose
exit status has already been collected.
.RE
.br
.ne 9
.P
The
.I facility
parameter encodes a default facility to be
assigned to all messages
that do not have an explicit facility already encoded:
.RS
.TP 20
\f4LOG_KERN\fP
Messages generated by the kernel.
These cannot be generated by any user processes.
.TP
\f4LOG_USER\fP
Messages generated by random user processes.
This is the default facility identifier if none is specified.
.TP
\f4LOG_MAIL\fP
The mail system.
.TP
\f4LOG_DAEMON\fP
System daemons, such as
\f4ftpd\f1(1M),
\f4routed\f1(1M),
etc.
.TP
\f4LOG_AUTH\fP
The authorization system:
\f4login\f1(1),
\f4su\f1(1),
\f4getty\f1(1M),
etc.
.TP
\f4LOG_LPR\fP
The line printer spooling system:
\f4lpr\f1(1),
\f4lpc\f1(1M),
etc.
.TP
\f4LOG_NEWS\fP
Reserved for the
.SM USENET
network news system.
.TP
\f4LOG_UUCP\fP
Reserved for the
.SM UUCP
system; it does not currently use
\f4syslog\f1.
.TP
\f4LOG_CRON\fP
The
\f4cron\f1/\f4at\f1
facility;
\f4crontab\f1(1),
\f4at\f1(1),
\f4cron\f1(1M),
etc.
.TP
\f4LOG_LOCAL0\-7\fP
Reserved for local use.
.RE
.P
\f4closelog\f1
can be used to close the log file.
.P
\f4setlogmask\f1
sets the log priority mask to
.I maskpri
and returns the previous mask.
Calls to
\f4syslog\f1
with a priority not set in
.I maskpri
are rejected.
The mask for an individual priority
.I pri
is calculated by the macro
\f4LOG_MASK\c\fP
\f4(\f2pri\fP);\f1
the mask for all priorities up to and including
.I toppri
is given by the macro
\f4LOG_UPTO\c\fP
\f4(\f2toppri\fP).\f1
The default allows all priorities to be logged.
.SH EXAMPLE
This call logs a message at priority
\f4LOG_ALERT\f1:
.P
.RS
\f5syslog(LOG_ALERT, "who: internal error 23");\fP
.RE
.P
The
.SM FTP
daemon,
\f4ftpd\f1,
would make this call to
\f4openlog\f1
to indicate that all messages it logs
should have an identifying string of
\f4ftpd\f1,
should be treated by
\f4syslogd\f1
as other messages from system daemons are,
and should include the process
.SM ID
of the process logging the message:
.P
.RS
\f5openlog("ftpd", LOG_PID, LOG_DAEMON);\fP
.RE
.P
Then it would make the following call to
\f4setlogmask\f1
to indicate that messages at priorities from
\f4LOG_EMERG\fP
through
\f4LOG_ERR\fP
should be logged, but that no messages at any
other priority should be logged:
.P
.RS
\f4setlogmask(LOG_UPTO\f1(LOG_ERR));\fP
.RE
.P
Then, to log a message at priority
\f4LOG_INFO\f1,
it would make the following call to
\f4syslog\f1:
.P
.RS
\f4syslog(LOG_INFO, "Connection from host %d", CallingHost);\fP
.RE
.P
A locally-written utility could use the following call to
\f4syslog\f1
to log a message at priority
\f4LOG_INFO\fP,
to be treated by
\f4syslogd\f1
as other messages to the facility
\f4LOG_LOCAL2\fP
are treated:
.P
.RS
\f4syslog(LOG_INFO|LOG_LOCAL2, "error: %m");\fP
.RE
.SH "SEE ALSO"
\f4logger\fP(1),
\f4login\fP(1),
\f4lpr\fP(1),
\f4lpc\fP(1M),
\f4syslogd\fP(1M),
\f4printf\fP(3S)
.P
\f4at\fP(1),
\f4crontab\fP(1),
\f4login\fP(1)
in the \f2User's Reference Manual\f1.
.br
\f4ftpd\fP(1M),
\f4routed\fP(1M)
in the \f2Network User's and Administrator's Guide\f1.
.br
\f4getty\fP(1M),
\f4cron\fP(1M),
\f4su\fP(1),
\f4printf\fP(3S)
in the \f2System Administrator's Reference Manual\f1.
