The syslogd daemon in a UNIX system is typically started by a system initialization script and runs continuously during system operation.
The SYSLOGD implementation originating from Berkeley performs the following steps at startup.
(1) Read the configuration file. Typically, the configuration file for/etc/syslog.conf specifies the various log messages that this daemon may charge, and how it should be handled.
(2) Create a UNIX domain datagram socket and give it a bundle of path names/var/run/log
(3) Create a UDP socket and bind it to Port 514.
(4) Open path name/dev/klog.
First, the Syslog function
#include <syslog.h>void syslog (intconstChar *message, ...); Priority: The combination of levels level and facility facility the message parameter resembles the printf format string, but adds %m, which is replaced with an error message corresponding to the current errno value.
The level of the log messages can be 0~7, they are arranged in order from high to low. If the sender does not specify a level value, then the default is Log_notice.
The log message contains a facility that identifies the type of message sending process. Default Log_user
For example, when rename unexpectedly fails, the daemon can execute the following call:
Syslog (log_info| Log_local2, "rename (%s,%s):%m", File1, file2);
#include <syslog.h>voidcharintint facility); void closelog (void);
Ident: There are syslog messages about each log message before the string. The usual value is the program name
Options: The logic or composition of one or more constant values
Facility
Parameters for options
UNP Learn the 13th Chapter daemon and inetd Super server