syslog 配置和使用(非syslog服务)

来源:互联网 发布:聊天套路知乎 编辑:程序博客网 时间:2024/05/27 21:05

在centos上,syslog其实是rsyslog,对应的配置文件为/etc/rsyslog.conf,守护进程为:/etc/rsyslog.d

//重启日志服务[root@localhost admin]# service rsyslog restart关闭系统日志记录器:                                       [确定]启动系统日志记录器:                                       [确定][root@localhost admin]# 

ref: http://www.linuxquestions.org/questions/linux-security-4/what-is-local0-through-local7-310637/

another thing is that :
local0-local7 are local facilities defined by the user, to log specific deamons

for example:
you can change the sshd_config file ( which is the configuration file of the sshd deamon )
from
Syslogfacility authpriv
to
Syslogfacility local7

and add the following line in the /etc/rsyslog.conf file
local7.* /var/log/sshd.log
after restarting rsyslogd and sshd, any ssh sessions to the server will be logged in the /var/log/sshd.log file


原文https://www.cnblogs.com/zwCHAN/p/3878209.html
unix类系统提供了系统范围的日志服务支持:syslogd。Syslogd启动时读配置文件/etc/syslog.conf。syslog.conf的每一行(#开头的为注释,将被忽略)由“选择符 动作”组成(selector action)。
选择符的形式为“设施.优先级”(facility.priority)。设施和优先级的名字都是系统提供的标准名字。
设施(facility):
kern 0 内核日志消息
user 1 随机的用户日志消息
mail 2 邮件系统日志消息
daemon 3 系统守护进程日志消息
auth 4 安全管理日志消息
syslog 5 syslogd本身的日志消息
lpr 6 打印机日志消息
news 7 新闻服务日志消息
uucp 8 UUCP系统日志消息
cron 9 系统始终守护进程crond的日志消息
authpriv 10 私有的安全管理日志消息
ftp 11 ftp守护进程日志消息
12~15 保留为系统使用
local0~local7 16~23保留为本地使用

优先级(priority),优先级越低情况越严重:
emerg 0 系统不可用
alert 1 必须马上采取行动的事件
crit 2 关键的事件
err 3 错误事件
warning 4 警告事件
notice 5 普通但重要的事件
info 6 有用的信息
debug 7 调试信息
可以用表示任何设施(句点前的)或任何优先级(句点后的*)。指定一个优先级的意思为大于等于该优先级的日志消息。可以用none表示不包括任何优先级。
Linux对bsd的syslog做了一些扩展,引入了’=’和’!’。可以在任何一个优先级前用’=’,表示仅仅针对该优先级而不包括大于它的优先级。’!’表示求反,可以放在优先级或’=’前面(如果有的话),表示和原来相反的意思。
具有相同优先级的几个设施可以一起写在句点前面,用’,’分开。具有相同动作的多个选择符可以写在同一行的选择符域,各个选择符之间用’;’分开。
一个合法的选择符为如下一些情况(举例说明):
1,. :任何设施的任何优先级的日志消息
1,local0.*: local0的任何优先级的日志消息
2,*.crit任何设施的优先级大于等于关键事件的日志消息
3,*.=crit 任何设施的关键事件日志消息
4,.;kern.none 除kern外的其他任何设施的任何日志消息
5,kern.info;kern.!err kern设施从info到warning之间的日志消息

动作域描述抽象名词”logfile”,一个”logfile”不必是一个真正的文件。Syslogd提供了如下的动作:
1,正常的文件,用文件的全路径名描述。路径名前加’-‘表示忽略同步文件。
2,命名管道(fifo)。在表示命名管道的文件全路径名前加”|”表示将日志写入命名管道。
3,终端和控制台。如/dev/console。
4,远程机器。“@hostname”
5,用户列表
6,登录的所有用户。用*表示。

日志函数:
void openlog(char *iden,int option,int facility)
void syslog(int priority,char *format);

日志消息格式: