How to use third-party log4j appenders in Nuxeo Tomcat distribution?

EDIT: At Julien Carsique's request I'll explain what I did to get Sentry logging working. We use Puppet for creating configuration files rather than Nuxeo templates, but the edits are so straightforward that it doesn't matter how it's done.

  1. Deploy a Sentry server and acquire the DSN for your Nuxeo system to access it.
  2. Download the raven-java jars and dependencies. I simply made a dummy Maven project and relied on dependency:copy-dependencies to acquire them. The jars should include raven-x.0.jar, raven-log4j-x.0.jar, jackson-core-2.2.0.jar, commons-codec-1.8.jar, slf4j-api-1.7.5.jar, and slf4j-log4j12-1.7.5.jar. You must match the Raven version (3.0 or 4.0) with the protocol used by your Sentry server.
  3. Copy these jars into NUXEO_HOME/server/lib (the Tomcat lib directory).
  4. Add code like the following to log4j.xml, which should be in the same directory:
<appender name="SENTRY" class="net.kencochrane.raven.log4j.SentryAppender">
  <param name="dsn" value="https://this-is-your-sentry-dsn-value-paste-it-in-exactly:1234/3"/>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="levelMin" value="WARN"/>
  </filter>
</appender>
<root>
   <level value="WARN" />
   <appender-ref ref="CONSOLE" />
   <appender-ref ref="FILE" />
   <appender-ref ref="SENTRY" />
</root>

My trouble below was caused by an invalid DSN – it didn't even resolve in DNS.

ORIGINAL QUESTION (fixed it myself):

I would like to use the raven-java Log4J appender to log notable events to a Sentry event console. I tried the simplest thing which could possibly work, which is to deploy the raven jars and their dependencies into Nuxeo's server/lib directory, and edit the log4j.xml to add a new appender. I receive the following error on startup:

2013-06-12 20:37:41,062 ERROR [org.nuxeo.runtime.tomcat.NuxeoLauncher] Failed to handle event
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.nuxeo.osgi.application.FrameworkBootstrap.start(FrameworkBootstrap.java:135)
        at org.nuxeo.runtime.tomcat.NuxeoLauncher.handleEvent(NuxeoLauncher.java:117)
        at org.nuxeo.runtime.tomcat.NuxeoLauncher.lifecycleEvent(NuxeoLauncher.java:88)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4700)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        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(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
        at net.kencochrane.raven.log4j.SentryAppender.buildEvent(SentryAppender.java:125)
        at net.kencochrane.raven.log4j.SentryAppender.append(SentryAppender.java:89)
        at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
        at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
        at org.apache.log4j.Category.callAppenders(Category.java:206)
        at org.apache.log4j.Category.forcedLog(Category.java:391)
        at org.apache.log4j.Category.log(Category.java:856)
        at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:193)
        at org.nuxeo.osgi.application.loader.FrameworkLoader.printStartMessage(FrameworkLoader.java:379)
        at org.nuxeo.osgi.application.loader.FrameworkLoader.doStart(FrameworkLoader.java:204)
        at org.nuxeo.osgi.application.loader.FrameworkLoader.start(FrameworkLoader.java:112)
        ... 31 more

This error is interesting because it seems to indicate that the new classes and configurations are available, but that something in the way Nuxeo starts within Tomcat makes the state of the Raven logging system invalid.

Is there something general I am missing about using third-party log4j appenders with Nuxeo/Tomcat, or is this problem specific to Raven?

1 votes

1 answers

3623 views

ANSWER



In order to answer my own question, this was caused by incorrect configuration of the Raven appender. This error apparently occurred before the appender of server.log was initialized. I wonder how to detect this class of error in general, since there was no indication of anything wrong in any of the Nuxeo-documented logs.

0 votes



You mean there were unlogged errors? Maybe starting the server in console would show them? Did you look into the other log files?
06/13/2013

Would you mind contribute or document a Raven Log4J configuration template? Regards.
06/13/2013

I looked in all the log files and didn't see anything. I assume that the error message complains about a bad initialization value in log4j.xml for the Sentry appender.

Right now I'm not deploying from source but rather from the APT package. I can write up what I'm doing with that installation, though.

06/13/2013

Strange you don't get an error, I'll try to reproduce it.

Yes, please, it would be nice for other users :)

06/13/2013

I added step-by-step instructions to the question above for now.
06/13/2013