如何配置Tomcat通过syslog记录所有内容?

时间:2010-07-27 09:40:43

标签: tomcat logging log4j jira syslog

我正在尝试配置Tomcat和webapp(Atlassian JIRA)以通过syslog记录所有内容。

以下是我添加到webapp log4j.properties(atlassian-jira / WEB-INF / classes / log4j.properties)的内容:

log4j.rootLogger=WARN, syslog
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.facility=LOCAL0
log4j.appender.syslog.layout.ConversionPattern=%-5p [%t] [%c]: %m%n
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.SyslogHost=my.syslog.server.fqdn

但是,没有任何内容通过syslog发送。我在端口514上嗅出了传出的数据包,但没有出现。

感谢您的帮助!

3 个答案:

答案 0 :(得分:3)

以下是我目前使用的解决方案:

  1. 我删除了conf / logging.properties文件
  2. 我修改了atlassian-jira / WEB-INF / classes / log4j.properties以禁用所有文件记录操作,只留下控制台记录
  3. 我修改了catalina.sh,以便将其输出传递给logger
  4. 我认为这个解决方案不符合java-world。但它正在发挥作用。

    但是,我仍然在寻找一种更简洁的方式来登录系统日志。

答案 1 :(得分:2)

我也非常喜欢JIRA的syslog appender,它不需要单独的记录器进程。

修改了/opt/jira/atlassian-jira/WEB-INF/classes/log4j.properties,如Q所示,相关结果如下:

...
23-Sep-2011 12:12:44 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
23-Sep-2011 12:12:44 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
log4j:ERROR Could not instantiate class [org.apache.log4j.net.SyslogAppender].
java.lang.ClassNotFoundException: org.apache.log4j.net.SyslogAppender
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.apache.log4j.helpers.Loader.loadClass(Loader.java:179)
        at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:320)
        at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:121)
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:664)
        at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
        at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
        at org.apache.log4j.Logger.getLogger(Logger.java:118)
        at com.atlassian.jira.startup.LauncherContextListener.<clinit>(LauncherContextListener.java:40)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4149)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
log4j:ERROR Could not instantiate appender named "syslog".
...

我可能错了,但看起来 org.apache.log4j.helpers.Loader.loadClass 类加载器知道 org.apache.log4j 包但是 NOT org.apache.log4j.net 包,即使它们位于同一个jar /opt/jira/lib/log4j-1.2.15.jar

撰写本文时:JIRA 4.4.1通过Linux 64位安装程序。

答案 2 :(得分:1)

对于访问日志:https://github.com/magwas/SyslogValve 可能需要调整你的tomcat版本,因为使用的api会不断变化。