在rsyslog.conf具体要怎么配置如下内容module(load="builtin:omfile" Template="huaweiUSGEvents") template(name="huaweiUSGEvents" type="string" string="/var/log/%fromhost-ip%/%PROGRAMNAME%-%$year%-%$month%-%$day%.log") template(name = "huaweiUSGEvents" type = "list" ) { property (name = "timestamp" dateFormat = "rfc3339" ) constant(value = " host=" ) property (name = "hostname" ) constant(value = ", relayHost=" ) property (name = "fromhost" ) constant(value = ", tag=" ) property (name = "syslogtag" ) constant(value = ", programName=" ) property (name = "programname" ) constant(value = ", procid=" ) property (name = "procid" ) constant(value = ", facility=" ) property (name = "syslogfacility-text" ) constant(value = ", sev=" ) property (name = "syslogseverity-text" ) constant(value = ", appName=" ) property (name = "app-name" ) constant(value = ", msg=" ) property (name = "msg" ) constant(value = "\n" ) }
时间: 2023-12-05 17:27:37 浏览: 179
在rsyslog.conf中添加如下配置:
```
# Load omfile module
module(load="builtin:omfile")
# Define huaweiUSGEvents template
template(name="huaweiUSGEvents" type="string" string="/var/log/%fromhost-ip%/%PROGRAMNAME%-%$year%-%$month%-%$day%.log")
# Define huaweiUSGEvents list template
template(name="huaweiUSGEventsList" type="list") {
property(name="timestamp" dateFormat="rfc3339")
constant(value=" host=")
property(name="hostname")
constant(value=", relayHost=")
property(name="fromhost")
constant(value=", tag=")
property(name="syslogtag")
constant(value=", programName=")
property(name="programname")
constant(value=", procid=")
property(name="procid")
constant(value=", facility=")
property(name="syslogfacility-text")
constant(value=", sev=")
property(name="syslogseverity-text")
constant(value=", appName=")
property(name="app-name")
constant(value=", msg=")
property(name="msg")
constant(value="\n")
}
# Send logs to huaweiUSGEvents file using huaweiUSGEvents template
if $programname == 'huaweiUSGEvents' then {
action(type="omfile" file="/var/log/huaweiUSGEvents.log" template="huaweiUSGEvents")
}
# Send logs to huaweiUSGEvents list using huaweiUSGEventsList template
if $programname == 'huaweiUSGEventsList' then {
action(type="omfile" file="/var/log/huaweiUSGEventsList.log" template="huaweiUSGEventsList")
}
```
这个配置会将符合条件的日志分别写入 `/var/log/huaweiUSGEvents.log` 和 `/var/log/huaweiUSGEventsList.log` 文件中,使用不同的模板格式化日志内容。其中,`huaweiUSGEvents` 模板用于格式化单条日志,`huaweiUSGEventsList` 模板用于格式化日志列表,包含了更详细的信息。
阅读全文