English 中文(简体)
我怎么能够改变当地东道方。
原标题:How can I change localhost.localdomain in the messages written by Log4j to the Linux syslog

我用Log4j及其SyslogAppender向Lino syslog发送了电文。 输出的信息类似:

Oct 12 09:06:03 localhost.localdomain 3364 [Thread-5] INFO TEST MESSAGE MyApplicationLogger - This is my message

我愿用管理应用程序的服务器名称取代当地主机,但似乎无法说明如何使用。 我的组合文件,如果有用的话:

log4j.logger.MyApplicationLogger=INFO, SyslogAppender
log4j.appender.SyslogAppender=org.apache.log4j.net.SyslogAppender
log4j.appender.SyslogAppender.syslogHost=localhost
log4j.appender.SyslogAppender.Facility=USER
log4j.appender.SyslogAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.SyslogAppender.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n
log4j.appender.SyslogAppender.source=My Application

Edit:计算机名称在服务器上配置,主名上报如下:

$ hostname
server12

不过,我确实注意到,东道国档案的第一线是:

127.0.0.1   localhost.localdomain localhost

然而,我犹豫不决,不能改变这种状况。

最佳回答

我对如何确定这一问题表示出看法,因此,如果其他人面临同样的问题,我也可以在此放弃解决办法。

在财产档案中:

log4j.appender.SyslogAppender.syslogHost=server12

不能肯定为什么它发挥作用,而是使用服务器名称而不是当地东道方为我工作。

问题回答

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.

如果你有根基的特权,你可以使用你的东道国名称。

$ hostname myServersHostname

rel=“nofollow”>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

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签