Implementation status: implemented

Synopsis

#include <syslog.h>

void closelog(void);
void openlog(const char *ident, int logopt, int facility);
int setlogmask(int maskpri);
void syslog(int priority, const char *message, ... /* arguments */);

Description

All these functions operate on the log file.
The syslog() function sends a message to the logging facility (/dev/log).
The openlog() function sets process attributes that affect subsequent calls to syslog().
The setlogmask() function sets the log priority mask for the current process to maskpri and returns the previous mask.
The closelog() function closes any open file descriptors allocated by previous calls to openlog() or syslog().

Arguments:
ident - a string that is written to all logs identifying the function or the situation, which generated the current log.
logopt - logging options,
facility - a logging facility,
maskpri - a log priority mask,

priority - a priority of the log,
message - a message to be put to the log.

The syslog() function sends a message to the logging facility (/dev/log). The logged message includes a message header and a message body. The message header contains a timestamp and a tag string. If logging device is not available, syslog() function puts the message to stderr.
The message body is generated from the message and arguments in the same manner as if these were arguments to printf(), except that the additional conversion specification %m is recognized; it converts no arguments, causes the output of the error message string associated with the value of errno on entry to syslog(), and may be mixed with argument specifications of the "%n$" form. If a complete conversion specification with the m conversion specifier character is not just %m, the behaviour is undefined. A trailing <newline> is also added.

As a severity level one of the following values is used:

LOG_EMERG A panic condition.
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 that may require special handling.
LOG_INFO Informational messages.
LOG_DEBUG Messages that contain information normally of use only when debugging a program.

Values of the priority argument are formed by OR'ing together a severity-level value and an optional facility value. If no facility value is specified, the current default facility value is used.

The facility indicates the application or system component generating the message. Possible facility values include:

LOG_USER Messages generated by arbitrary processes. This is the default facility identifier if none is specified.
LOG_LOCAL0 Reserved for local use.
LOG_LOCAL1 Reserved for local use.
LOG_LOCAL2 Reserved for local use.
LOG_LOCAL3 Reserved for local use.
LOG_LOCAL4 Reserved for local use.
LOG_LOCAL5 Reserved for local use.
LOG_LOCAL6 Reserved for local use.
LOG_LOCAL7 Reserved for local use.

The openlog() function sets process attributes that affect subsequent calls to syslog() that is among others the path to the log file and a default facility.

The logopt argument indicates logging options. Values for logopt are constructed by a bitwise-inclusive OR of zero or more of the following:

LOG_PID Log the process ID with each message. This is useful for identifying specific processes.
LOG_CONS Write messages to the system console if they cannot be sent to the logging facility. The syslog() function ensures that the process does not acquire the console as a controlling terminal in the process of writing the message.
LOG_NDELAY Open the connection to the logging facility 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.
LOG_ODELAY Delay open until syslog() is called.
LOG_NOWAIT Do not wait for child processes that may have been created during the course of logging the message. 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 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 default log mask allows all priorities to be logged. A call to openlog() is not required prior to calling setlogmask().

Symbolic constants for use as values of the logopt, facility, priority, and maskpri arguments are defined in the <syslog.h> header.

Return value

The closelog(), openlog(), and syslog() functions do not return a value.
The setlogmask() function returns the previous log priority mask.

Errors

No errors are defined.

Implementation tasks