closelog, openlog, setlogmask, syslog - control system log
#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 */);
The syslog() function shall send a message to an implementation-defined logging facility, which may log it in an implementation-defined system log, write it to the system console, forward it to a list of users, or forward it to the logging facility on another host over the network. The logged message shall include a message header and a message body. The message header contains at least a timestamp and a tag string.
The message body is generated from the message and following arguments in the same manner as if these were arguments to printf(), except that the additional conversion specification %m shall be recognized; it shall convert no arguments, shall cause 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 behavior is undefined. A trailing <newline> may be added if needed.
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.
Possible values of severity level include:
Warning messages.
The facility indicates the application or system component generating the message. Possible facility values include:
The openlog() function shall set process attributes that affect subsequent calls to syslog(). The ident argument is a string that is prepended to every message. 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 shall close any open file descriptors allocated by previous calls to openlog() or syslog().
The setlogmask() function shall set the log priority mask for the current process to maskpri and return 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 shall be 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.
The setlogmask() function shall return the previous log priority mask. The closelog(), openlog(), and syslog() functions shall not return a value.
No errors are defined.
The following sections are informative.
The following example causes subsequent calls to syslog() to log the process ID with each message, and to write messages to the system console if they cannot be sent to the logging facility.
#include <syslog.h> char *ident = "Process demo"; int logopt = LOG_PID | LOG_CONS; int facility = LOG_USER; ... openlog(ident, logopt, facility);
The following example causes subsequent calls to syslog() to accept error messages, and to reject all other messages.
#include <syslog.h> int result; int mask = LOG_MASK (LOG_ERR); ... result = setlogmask(mask);
The following example sends the message "This is a message" to the default logging facility, marking the message as an error message generated by random processes.
#include <syslog.h> char *message = "This is a message"; int priority = LOG_ERR | LOG_USER; ... syslog(priority, message);
printf() , the Base Definitions volume of IEEE Std 1003.1-2001, <syslog.h>
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |