Rsyslog 在配置中使用 else

Rsyslog using else in config

嗨,我需要配置文件:

if $FROMHOST-IP == '192.168.xx.xxx' then { action(type="omfile" file="/var/log/rsyslog/myHostName/device.log") }
else {*.* ?RemoteHost}

但是重启后的 rsyslog 给我这条消息:

Oct 13 12:12:40 syslog-new rsyslogd[29378]: error during parsing file /etc/rsyslog.conf, on or before line 118: syntax error on token 'else' [v8.1901.0 try https://www.rsyslog.com/e/2207 ]
Oct 13 12:12:40 syslog-new rsyslogd[29378]: could not interpret master config file '/etc/rsyslog.conf'. [v8.1901.0 try https://www.rsyslog.com/e/2207 ]

请帮忙。 谢谢

关于 if..then..else 的 RainerScript 文档有些缺乏细节,但为了将 if 的这种用法与同样从 [=11= 开始的旧过滤器语法区分开来], 看来你需要把表达式括在 () 中。尝试

if ($FROMHOST-IP == '192.168.xx.xxx') then { action(type="omfile" file="/var/log/rsyslog/myHostName/device.log") }
else {*.* ?RemoteHost}