|SYSLOG(3C)||Standard C Library Functions||SYSLOG(3C)|
#include <syslog.h> void openlog(const char *ident, int logopt, int facility);
void syslog(int priority, const char *message, .../* arguments */);
int setlogmask(int maskpri);
The message body is generated from the message and following arguments in the same manner as if these were arguments to printf(3C), 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, facility, priority, and maskpri arguments are defined in the <syslog.h> 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:
The facility indicates the application or system component generating the message. Possible facility values include:
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 making a private copy of it. The logopt argument indicates logging options. Values for logopt are constructed by a bitwise-inclusive OR of zero or more of the following:
The facility argument encodes a default facility to be assigned to all messages that do not have an explicit facility already encoded. The initial default facility is LOG_USER.
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 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 log mask allows all priorities to be logged.
This call logs a message at priority LOG_ALERT:
syslog(LOG_ALERT, "who: internal error 23");
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(8) as other messages from system daemons are, should include the process ID 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(8) as other messages to the facility LOG_LOCAL2 are:
syslog(LOG_INFO|LOG_LOCAL2, "error: %m");
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|
|May 13, 2017||OmniOS|