问题描述
我正在尝试使logback syslog附加程序正常工作,并且我肯定配置有误.我已经创建了一个小型示例项目,我认为它应该记录到syslog中,但事实并非如此. /p>
我确定我缺少一些愚蠢的东西.这是来自 logback.xml 的附加程序:
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>localhost</syslogHost>
<facility>USER</facility>
<suffixPattern>[%thread] %logger %msg</suffixPattern>
</appender>
我尝试过显式添加端口(514),这并不令人高兴.在我尝试过的两个系统上,我都已验证syslog是否使用logger "test message"
接收输入,然后尾随/var/log/messages或/var/log/system.log.
为了将logback/slf4j记录到syslog,我需要更改什么?
您的代码没有任何问题,问题在于系统配置.使用您提供的测试项目,我能够使syslog附加程序正常工作(Ubuntu 14.10).
以下是一些步骤:
- 编辑
/etc/syslog.conf
并确保已启用网络系统日志:
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# provides TCP syslog reception
# note that logback seems to use UDP, so this isn't strictly necessary.
$ModLoad imtcp
$InputTCPServerRun 514
- 如果更改配置,请重新启动rsyslog(
service rsyslog restart
)(重新加载无效) - 检查syslog是否正在使用
lsof -i | grep syslog
进行监听
结果:
I'm trying to get a logback syslog appender working, and I've definitely got something misconfigured. I've created a small sample project which I think should log to syslog, yet it doesn't.
I'm sure I'm missing something stupid. Here's the appender from logback.xml:
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>localhost</syslogHost>
<facility>USER</facility>
<suffixPattern>[%thread] %logger %msg</suffixPattern>
</appender>
I've tried adding the port (514) explicitly, and, no joy. on both systems I've tried this on, I've verified syslog is receiving input using logger "test message"
and then tailing either /var/log/messages or /var/log/system.log.
What do I need to change in order to get logback/slf4j logging to syslog?
Nothing is wrong with your code, the problem is the system config.Using your provided test project, I was able to make the syslog appender work (Ubuntu 14.10).
Here are some steps:
- edit
/etc/syslog.conf
and ensure you have network syslog enabled:
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# provides TCP syslog reception
# note that logback seems to use UDP, so this isn't strictly necessary.
$ModLoad imtcp
$InputTCPServerRun 514
- restart rsyslog (
service rsyslog restart
) if you change the config (reload doesn't work) - check that syslog is listening with
lsof -i | grep syslog
results:
这篇关于我的logback syslog追加程序出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!