syslog 格式学习
来源:互联网 发布:淘宝店铺图标怎么设置 编辑:程序博客网 时间:2024/06/05 08:23
完整的syslog消息由3部分组成,分 别是PRI、HEADER和MSG。大部分syslog都包含PRI和MSG部分,而HEADER可能没有。
下面是一个syslog消息:
<30>Oct 9 22:33:20 hlfedora auditd[1787]: The audit daemon is exiting.
其中“<30>”是PRI部分,“Oct 9 22:33:20 hlfedora”是HEADER部分,“auditd[1787]: The audit daemon is exiting.”是MSG部分。
1、PRI部分
PRI部分由尖括号包含的一个数字构成(即Priority,取值0~191)。这个数字包含两个信息:Facility和Level。可以把Facility看做是创建日志消息的实体(例如是计算机内核还是用户程序),把Level看做是日志真正的级别(非为8个等级,后边会给出)。其中,Priority=Facility * 8 + Level。
The list of Facilities available:
0 kernel messages
1 user-level messages
2 mail system
3 system daemons
4 security/authorization messages
5 messages generated internally by syslogd
6 line printer subsystem
7 network news subsystem
8 UUCP subsystem
9 clock daemon
10 security/authorization messages
11 FTP daemon
12 NTP subsystem
13 log audit
14 log alert
15 clock daemon
16 local use 0 (local0)
17 local use 1 (local1)
18 local use 2 (local2)
19 local use 3 (local3)
20 local use 4 (local4)
21 local use 5 (local5)
22 local use 6 (local6)
23 local use 7 (local7)
Facility的定义如下,可以看出来syslog的Facility是早期为Unix操作系统定义的,不过它预留了User(1),Local0~7 (16~23)给其他程序使用。
The list of severity Levels:
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 Informational: informational messages
7 Debug: debug-level messages
A detailed explanation of the severity Levels:
DEBUG:
Info useful to developers for debugging the app, not useful during operations
INFORMATIONAL:
Normal operational messages - may be harvested for reporting, measuring throughput, etc - no action required
NOTICE:
Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required
WARNING:
Warning messages - not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time
ERROR:
Non-urgent failures - these should be relayed to developers or admins; each item must be resolved within a given time
ALERT:
Should be corrected immediately - notify staff who can fix the problem - example is loss of backup ISP connection
CRITICAL:
Should be corrected immediately, but indicates failure in a primary system - fix CRITICAL problems before ALERT - example is loss of primary ISP connection
EMERGENCY:
A "panic" condition - notify all tech staff on call? (earthquake? tornado?) - affects multiple apps/servers/sites...
在生成的日志消息中,Priority=Facility * 8 + Level,
例如: 15 = 1 * 8 + 7
在日志服务器对该消息的级别进行解析时,Facility = Priority / 8; Level = Priority % 8;
例如: 1 = 15 / 8; 7 = 15 % 8;
2、HEADER部分
HEADER部分包括两个字段,时间和主机名(或IP)。
时间紧跟在PRI后面,中间没有空格,格式必须是“Mmm dd hh:mm:ss”,不包括年份。“日”的数字如果是1~9,前面会补一个空格(也就是月份后面有两个空格),而“小时”、“分”、“秒”则在前面补“0”。月份取值包括:
Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
时间后边跟一个空格,然后是主机名或者IP地址,主机名不得包括域名部分。
HEADER部分后面跟一个空格,然后是MSG部分。
有些syslog中没有HEADER部分。这个时候MSG部分紧跟在PRI后面,中间没有空格。
3、MSG部分
MSG部分又分为两个部分,TAG和Content。其中TAG部分是可选的。
在 前面的例子中(“<30>Oct 9 22:33:20 hlfedora auditd[1787]: The audit daemon is exiting.”),“auditd[1787]”是TAG部分,包含了进程名称和进程PID。PID可以没有,这个时候中括号也是没有的。
进程PID有时甚至不是一个数字,例如“root-1787”,解析程序要做好容错准备。
TAG后面用一个冒号隔开Content部分,这部分的内容是应用程序自定义的。
4、RFC3195
BSD syslog协议使用UDP协议在网络中传递,然而UDP是一个不可靠的协议,并且syslog也没有要求接收方有所反馈。为了解决这个问题,RFC又定义了一个新的规范来可靠的传递syslog消息,它使用TCP协议:
http://www.ietf.org/rfc/rfc3195.txt
不过大多数情况下,使用UDP发送不需要确认的syslog消息,已经能够满足要求了,并且这样做非常简单。因此到目前为止,RFC3195的应用还是很少见的。
Kiwi Syslog Server 是一个免费的Windows平台上的syslog守护进程。它接收,记录,显示和转发系统日志,如路由器,防火墙,交换机,Unix主机和其他功能的设备主机的syslog消息。有许多可供自定义的选项。其特点包括PIX防火墙日志记录,Linksys的家庭防火墙日志,SNMP陷阱和TCP的支持,有能力进行筛选,分析和修改信息,并透过VBScript或JScript引擎执行动作。注册版有附加功能。http://www.cr173.com/soft/20677.html
感谢引文:
在2001年定义的RFC3164中,描述了BSD syslog协议:http://www.ietf.org/rfc/rfc3164.txt
引文:http://areyouok.iteye.com/blog/251590
http://blog.csdn.net/donhao/article/details/5592204
- syslog 格式学习
- Syslog格式
- syslog格式
- syslog格式
- Syslog学习
- Syslog格式说明
- syslog 协议及格式
- python之syslog学习
- syslog-ng 学习
- SysLog 学习的一点思路
- SysLog 学习的一点思路
- SYSLOG 的学习和使用
- SysLog 学习的一点思路
- syslog
- syslog
- Syslog
- Syslog
- SYSLOG
- Delphi练习四——窗体间跳转(用户登录)
- VM ware 安装 Linux 手记
- 自己编译的android sdk无法识别各版本platform的问题
- 数据结构常见题(1)表
- 四种类型转换 cast
- syslog 格式学习
- 完美解决翻页效果
- WIN7下添加PROTEL 99 SE 库不成功解决方案
- 成功人士的人生理念
- Android 模拟键盘鼠标事件(Socket+Instrumentation实现)
- hibernate缓存
- TI Davinci DM6441嵌入式Linux移植攻略——开发环境搭建篇
- Delphi练习五——文本编辑器(简单)
- CruiseControl最佳实践