开发者

How to configure Tomcat to log everything via syslog?

开发者 https://www.devze.com 2023-01-09 05:13 出处:网络
I\'m trying to configure Tomcat and a webapp (Atlassian JIRA) to log everything over syslog. Here is what I added to the webapp log4j.properties (atlassian-jira/WEB-INF/classes/log4j.properties) :

I'm trying to configure Tomcat and a webapp (Atlassian JIRA) to log everything over syslog.

Here is what I added to the 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开发者_JS百科.ConversionPattern=%-5p [%t] [%c]: %m%n
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.SyslogHost=my.syslog.server.fqdn

However, nothing is sent over syslog. I sniffed outgoing packets on the port 514 and nothing appears.

Thanks for your help!


Here is the solution I currently use :

  1. I removed the conf/logging.properties file
  2. I modified the atlassian-jira/WEB-INF/classes/log4j.properties in order to disable all file logging operations, leaving only console logging
  3. I modified catalina.sh in order to pipe its output to logger

I imagine this solution isn't java-world-compliant. But it's working.

However, I'm still looking for a cleaner way to log to syslog.


I also would really like a syslog appender for JIRA that doesn't require a separate logger process.

Modified /opt/jira/atlassian-jira/WEB-INF/classes/log4j.properties as indicated in the Q with relevant result as follows:

...
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".
...

I could be wrong, but it looks like the org.apache.log4j.helpers.Loader.loadClass class loader knows about the org.apache.log4j package but NOT org.apache.log4j.net package even though they reside in the same jar /opt/jira/lib/log4j-1.2.15.jar.

At time of writing: JIRA 4.4.1 via Linux 64-bit Installer.


For access logs: https://github.com/magwas/SyslogValve It might needs tweaking for your tomcat version through, as the used api is constantly changing.

0

精彩评论

暂无评论...
验证码 换一张
取 消