Syslog introduction (original, extracted from my 2001 technical notes)

zhaozj2021-02-16  48

UNIX class systems provide system-wide log service support: syslogd. Syslogd is read when reading the configuration file /etc/syslog.conf. Each row of syslog.conf (# 开 的 开 注, will be ignored) consisting of "Selector action".

The selection is "facility. Priority" (facility.priority). The names of the amenities and priority are the standard names provided by the system.

Facility:

KERN 0 kernel log message

User 1 Random User Log Message

Mail 2 Mail System Log Message

Daemon 3 system daemon log message

Auth 4 Security Management Log Message

Syslog 5 syslogd itself log message

LPR 6 printer log message

News 7 News Service Log Message

UUCP 8 UUCP System Log Message

Cron 9 system always daemon log messages

Authpriv 10 private security management log message

FTP 11 FTP daemon log message

12 ~ 15 Reserved for system use

Local0 ~ Local7 16 ~ 23 is reserved for local use

Priority, the lower the situation, the more serious:

Emerg 0 system is not available

Alert 1 must take an event immediately

CRIT 2 Key Events

Err 3 error event

WARNING 4 Warning Event

NOTICE 5 ordinary but important events

INFO 6 useful information

Debug 7 debugging information

You can use * to indicate any facility (*) or any priority (* after the period). Specifies a priority to a log message greater than or equal to the priority. You can use none to indicate that no priority is included.

Linux has made some extensions to the Syslog of BSD, introduced to '=' and '!'. You can use '=' before any priority, indicating that only the priority is greater than its priority. '!' Indicates that the reversion can be placed in front of the priority or '=' (if any), indicating that it means to the opposite. Several facilities with the same priority can be written together in front of the period, separated by ','. A plurality of selectors having the same action can be written in the selective field of the same row, and each selector is separated from ';' separate.

A legal selector is some cases (for example):

1, *. *: Any priority log message for any facility

1, local0. *: Any priority log message for local0

2, *. CRIT Any facility priority is greater than log messages for key events

3, *. = Cries for any facility key event log message

4, *. *; Kern.none Any log message in any other facility except Kern

5, kern.info; kern.! ERR KERN facility from INFO to WARNING log message

Action domain describes abstract nouns "logfile", a "logfile" does not have to be a real file. Syslogd provides the following action:

1. Normal files, describe the full path name of the file. The path name before adding '-' means ignoring the synchronization file.

2, named the pipe (FIFO). In order to write a full path of the file that represents a named pipe, "|" means writing the log into a naming pipe.

3, terminals and consoles. Such as / dev / console.

4, remote machine. "@Hostname"

5, list of users

6. All users logged in. Use *.

Log function:

Void OpenLog (Char * Ideen, Int Option, Int Facility)

Void Syslog (int priority, char * format);

Log message format:

Ident: Formatted String

In order to use the powerful log feature provided by Syslogd, you can use these log functions in the log system.

In OpenLog, Option generally takes 0, the facility is these defined above, but with the following constants:

LOG_AUTH AUTH

LOG_AUTHPRIV Authpriv

Log_cron cron

Log_daemon daemon

LOG_KERN KERN

LOG_LOCAL0 ~ LOG_LOCAL7 LOCAL0 ~ LOCAL7

LOG_LPR LPR

LOG_MAIL MAIL

LOG_NEWS NEWS

LOG_SYSLOG SYSLOG

Log_User User

LOG_UUCP UUCP

Priority in the syslog () function is the priorities mentioned above, here the following constant is used

LOG_EMERG EMERG

LOG_ALERT ALERT

Log_crit critlog_err ERR

Log_Warning Warning

LOG_NOTICE NOTICE

LOG_INFO INFO

LOG_DEBUG Debug

The Format in syslog () is the same as Printf (Char * Format).

For example, you can use OpenLog in the IKE module ("IKE", 0, LOG_LOCAL0)

Then when you need to do logs, such as encrypted cards, you are faulty:

Syslog (log_emerg, "sjy01-a cipher crash!");

转载请注明原文地址:https://www.9cbs.com/read-23218.html

New Post(0)