How can I change localhost.localdomain in the messages written by Log4j to the Linux syslog

假装没事ソ 提交于 2019-12-03 09:54:24

This is what you need:

log4j.appender.SyslogAppender.header = true

This issue is because your machine doesn't know it's own host name. This can be demonstrated by running the command hostname as a non-privileged user.

If you have root privileges then you can set your host name using

$ hostname myServersHostname

man page

To make this change permanent across reboots you will need to set a configuration file somewhere in /etc (exactly which one depends on your distro).

  • Debian/ubuntu: /etc/hostname
  • Redhat/CentOS/Fedora: /etc/sysconfig/network

I figured out how to fix it, so I might as well leave the solution here in case other people face the same problem.

In the properties file, put this:

log4j.appender.SyslogAppender.syslogHost=server12

Not sure why it works, but using the server name instead of localhost worked for me.

If you don't want to 'hard code' the hostname in the log4j properties or XML file, the best solution is a combination of what is suggested by dtyler and yegor256. Make sure your hostname is set correctly, and then use log4j.appender.SyslogAppender.header = true or <param name="Header" value="true"/> in your log4j.xml

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