[Linux manuál]
Návod, kniha: POSIX Programmer's Manual
void closelog(void);
void openlog(const char * ident, int
logopt , int
facility);
int setlogmask(int maskpri);
void syslog(int priority, const char
*message , ... /*
arguments */);
closelog, openlog, setlogmask, syslog: log systému řízení
Originální popis anglicky: closelog, openlog, setlogmask, syslog - control system logNávod, kniha: POSIX Programmer's Manual
STRUČNĚ
#include <syslog.h>POPIS / INSTRUKCE
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:- 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.
- 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.
- 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.
NÁVRATOVÁ HODNOTA
The setlogmask() function shall return the previous log priority mask. The closelog(), openlog(), and syslog() functions shall not return a value.CHYBY / ERRORY
No errors are defined. The following sections are informative.PŘÍKLADY POUŽITÍ
Using openlog()
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);
Using setlogmask()
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);
Using syslog
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);
APPLICATION USAGE
None.RATIONALE
None.FUTURE DIRECTIONS
None.SOUVISEJÍCÍ
printf() , the Base Definitions volume of IEEE Std 1003.1-2001, <syslog.h>COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .| 2003 | IEEE/The Open Group |