What's wrong with my logback syslog appender?

霸气de小男生 提交于 2020-01-04 01:30:59

问题


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?


回答1:


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:



来源:https://stackoverflow.com/questions/29548028/whats-wrong-with-my-logback-syslog-appender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!