Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

closelog, openlog, setlogmask, syslog - control system log

&pagelevel(4)&pagelevel

Syntax

#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

By default syslog() writes a message message to the /var/adm/messages file. Optionally the system administrator can also define different log files for the syslog daemon. Details of how the syslog daemon works and is controlled are provided in the "POSIX Basics" manual [1 (Related publications)].

The message consists of a message header and the message text. The message header contains the specification of the message weight, the time specification, the syslog ID and, optionally, the process ID.

The message text is created from the message argument and the subsequent arguments as though these arguments had been passed to printf(), except that %m in the format string to which message points is replaced by the error message that corresponds to the current value of errno. A trailing newline character is added if necessary.

Values for priority are formed by inclusive OR from the message weight and, if applicable, the function value. If no function was specified for facility, the predefined default function is used.

Possible values for the message weight are: 

 

LOG_EMERG

A “panic“ condition. This condition is normally passed to all users.

 

LOG_ALERT

A condition that should be corrected immediately, e.g. a damaged system database.

 

LOG_CRIT

Critical condition, e.g. device error.

 

LOG_ERR

Error.

 

LOG_WARNING

Warning messages.

 

LOG_NOTICE

Conditions which do not involve error conditions but may require special steps.

 

LOG_INFO

LOG_DEBUG

Information messages.
Messages containing information which are normally only used during program debugging.

 

facility indicates which application or which system component has generated the message. Possible values are:

 

LOG_USER

Messages created by optional user processes. This is the default function ID if no other one 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.

 

openlog() sets process attributes which control subsequent calls of syslog(). The ident argument is a string that is prefixed to every message. logopt is a bit field in which log options are displayed. Values for logopt are generated from any number of the following values via bit-wise inclusive OR. The following are current values for logopt:

 

LOG_PID

Logs the process ID with each message. This is useful for the identification of special processes.

 

LOG_CONS

Outputs messages on the system console if they cannot be written to the log file (by default: /var/adm/syslog) . This option can be used safely in processes which do not have a control terminal, because syslog() generates a child process before the console is opened.

 

LOG_NDELAY

Opens the log file (by default: /var/adm/syslog) on execution of openlog(). Normally the opening is delayed until the first message is logged. This option is useful for programs which have to pay attention to the sequence when allocating file descriptors.

 

LOG_ODELAY

Delays the opening until syslog() is called.

 

LOG_NOWAIT

Does not wait for child processes which were split up for the logging of messages on the console. This option should be used by processes which, with the help of SIGCHLD, output notification of the termination of a child process, otherwise syslog() might be blocked by the wait for a child process whose end status has already been reached.


The facility argument encodes a standard function which is to be assigned to all messages that do not have an already encoded explicit function. The default for the standard function is LOG_USER.

The openlog() and syslog() functions can assign file descriptors. It is not necessary to call openlog() before syslog().

The closelog() function closes all open file descriptors that were assigned by previous calls of openlog() and syslog().

setlogmask() sets the log priority mask for the current process to maskpri and returns the previous mask. If maskpri has the value 0, the current log priority mask is not changed.
syslog() calls by the current process whose priority is not specified in maskpri are rejected. The mask for a specific priority pri is computed from the LOG_MASK(pri) macro.
The masks for all priorities up to and including toppri are specified in the LOG_UPTO(toppri) macro. By default all priorities can be logged.

Symbolic constants which are used as values for logopt, facility, priority and maskpri are defined in the syslog.h header file. 

Return val.

setlogmask():

Previous log priority mask. 

See also

printf(), syslog.h.