You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

rsyslog必填字段未显示问题排查求助

RSyslog日志字段缺失及原始消息查看解决方案

1. 是否为RSyslog模板配置错误?

是的,大概率是模板配置问题。你当前使用的logstreamingfmt是rsyslog预定义模板,它并不包含需求中的全部必填字段(比如facility_code、severity_code、Program等)。要输出所有指定字段,必须自定义模板,明确映射每个字段对应的rsyslog变量。

示例自定义模板配置:

# 定义包含所有必填字段的模板
template(name="customLogFormat" type="list") {
  constant(value="{")
  property(name="pri" outname="Priority" format="jsonf")
  constant(value=", ")
  property(name="hostname" outname="Hostname" format="jsonf")
  constant(value=", ")
  property(name="programname" outname="Program" format="jsonf")
  constant(value=", ")
  property(name="syslogtag" outname="TAG" format="jsonf")
  constant(value=", ")
  property(name="msg" outname="Message" format="jsonf")
  constant(value=", ")
  property(name="syslogfacility" outname="facility_code" format="jsonf")
  constant(value=", ")
  property(name="syslogfacility-text" outname="facility" format="jsonf")
  constant(value=", ")
  property(name="syslogseverity-text" outname="Severity" format="jsonf")
  constant(value=", ")
  property(name="syslogseverity" outname="severity_code" format="jsonf")
  constant(value=", ")
  property(name="timereported" outname="Timestamp" format="jsonf" dateFormat="rfc3339")
  constant(value="}\n")
}

# 替换原有输出规则,使用自定义模板
action(type="omfile" file="/var/log/log-transformer.log" template="customLogFormat")

修改配置后需重启rsyslog服务:systemctl restart rsyslog

2. 如何在RSyslog服务器查看上游发送的原始消息?

推荐两种可靠方法:

方法一:临时配置输出原始日志

在rsyslog配置中添加临时规则,将未解析的原始日志输出到独立文件:

# 临时输出原始消息到raw.log
action(type="omfile" file="/var/log/raw-messages.log" template="RSYSLOG_TraditionalFileFormat")

该模板会保留上游发送的原始日志结构,包含所有未被rsyslog处理的字段。配置生效后查看/var/log/raw-messages.log即可,测试完成后可删除该规则并重启服务。

方法二:抓包捕获原始流量

使用tcpdump直接捕获514端口的UDP/TCP流量,获取最原始的日志数据:

# 捕获UDP 514端口流量
tcpdump -i any udp port 514 -v -A

# 捕获TCP 514端口流量
tcpdump -i any tcp port 514 -v -A

-A参数会以ASCII格式打印数据包内容,可直接查看原始日志文本。

内容的提问来源于stack exchange,提问作者Anshul Singhal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 00:42:23