|
|
#include <syslog.h>
void openlog(char *ident, int logopt, int facility);
void syslog(int priority, char *logstring, /* parameters */ ...);
void closelog(void);
int setlogmask(int maskpri);
Safe
syslog() passes a message to syslogd.1m which may append it to a log file, write it to the system console, or forward it (to either a list of users or syslogd on another host on the network), depending on the configuration of /etc/syslog.conf. logstring is tagged with a priority of priority, and looks like a printf.3b string with one additional allowable format specification, %m, which is replaced with the error message string corresponding to the error number in errno. A trailing NEWLINE is added if needed. Options passed to openlog() may cause the size of the message to expand. The maximum size of the message passed to syslogd is 1024 bytes.
Priorities are encoded as a facility and a level. The facility describes the part of the system generating the message. The level is selected from the bitwise inclusive OR of zero or more of the following flags, defined in the header <syslog.h>.
If special processing is needed, openlog() can be called to initialize the log file. The parameter ident is a string that is prepended to every message. logopt is a bit field indicating logging options. Values for logopt are:
The facility parameter encodes a default facility to be assigned to all messages that do not have an explicit facility already encoded:
closelog() can be used to close the log file.
setlogmask()
sets the log priority mask to
maskpri
and returns the previous mask.
Calls to
syslog()
with a priority not set in
maskpri
are rejected.
The mask for an individual priority
pri
is calculated by the macro
LOG_MASK(pri);
the mask for all priorities up to and including
toppri
is given by the macro
LOG_UPTO(toppri).
The default allows all priorities to be logged.
The FTP 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.1m as other messages from system daemons are, should include the process ID of the process logging the message:
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:
A locally-written utility could use the following call to syslog() to log a message at priority LOG_INFO to be treated by syslogd.1m as other messages to the facility LOG_LOCAL2 are:
|
|
Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97