温馨提示×

Debian syslog格式是什么

小樊
42
2026-08-18 02:36:27
栏目: 智能运维

Debian 系统上的 syslog 格式通常遵循 RFC 3164(BSD syslog) 规范,但在较新版本中也支持 RFC 5424。下面按常见情况说明。


一、传统 syslog 格式(最常见,RFC 3164)

这是 Debian 默认 /var/log/syslog 中最常见的格式:

<优先级> 时间戳 主机名 进程[PID]: 消息内容

示例

<34>Jan 21 10:23:01 debian sshd[1234]: Accepted password for user1 from 192.168.1.10 port 22

字段说明

字段 说明
<34> 优先级(Priority),含 facility + severity
Jan 21 10:23:01 时间戳(无年份)
debian 主机名
sshd[1234] 进程名和 PID
Accepted password ... 日志消息

二、优先级(Priority)

优先级 = Facility × 8 + Severity

Severity(严重级别)

含义
0 emergency
1 alert
2 critical
3 error
4 warning
5 notice
6 informational
7 debug

例如:

<34> = 4 (auth) × 8 + 2 (critical)

三、Debian 使用的 syslog 实现

1️⃣ rsyslog(最常见)

Debian 默认使用 rsyslog,日志格式仍为传统 syslog。

配置文件:

/etc/rsyslog.conf
/etc/rsyslog.d/*.conf

日志位置:

/var/log/syslog
/var/log/auth.log
/var/log/kern.log

四、RFC 5424 格式(较新,可选)

开启后格式为:

<优先级>1 时间戳 主机名 应用名 进程ID 消息ID 结构化数据 消息

示例

<34>1 2026-01-21T10:23:01.123Z debian sshd 1234 - - Accepted password

特点:

  • ISO8601 时间戳
  • 支持 结构化数据
  • 默认 未启用

五、systemd journal 日志格式(非 syslog)

Debian 使用 systemd 后,日志还可通过 journald 查看:

journalctl

journal 日志是 二进制格式,包含:

  • 时间戳
  • 服务名
  • PID
  • UID
  • 内核/用户区分

journalctl -o short 可输出类似 syslog 的文本格式。


六、总结

✅ Debian 默认 syslog 格式(rsyslog)

<优先级> 时间戳 主机名 进程[PID]: 消息

✅ 实际使用的是 RFC 3164
✅ 可通过 rsyslog 配置切换为 RFC 5424
✅ systemd journal 使用独立二进制格式

如果你需要:

  • 解析 syslog 的正则
  • 自定义 rsyslog 模板
  • 对比 syslog 与 journal

可以继续问我。

0