0

I'm trying to use raven-log4j to send youtrack's exception to the Sentry.

/etc/youtrack/log4j.xml:

<appender name="sentry" class="net.kencochrane.raven.log4j.SentryAppender">
  <param name="dsn" value="https://publicKey:secretKey@host:port/1"/>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="levelMin" value="WARN"/>
  </filter>
</appender>

<root>
    <priority value="INFO"/>
    <appender-ref ref="SYSLOG"/>
    <appender-ref ref="sentry"/>
</root>

A part of the original upstart file:

exec java -Xmx{{ heap_size }} -XX:MaxPermSize=250m -Djava.awt.headless=true -Djetbrains.youtrack.disableBrowser=true -Djava.security.egd=/dev/zrandom -Djetbrains.mps.webr.log4jPath=/etc/youtrack/log4j.xml -jar /usr/local/youtrack/{{ jarfile }} 8082

and I changed it to:

exec java -Xmx1g -XX:MaxPermSize=250m -Djava.awt.headless=true -Djetbrains.youtrack.disableBrowser=true -Djava.security.egd=/dev/zrandom -Djetbrains.mps.webr.log4jPath=/etc/youtrack/log4j.xml -cp /usr/local/youtrack/youtrack-6.5.16853.jar:/usr/local/youtrack/lib/* jetbrains.youtrack.standalone.YoutrackStandalone 8082

to specify the classpath (/usr/local/youtrack/lib/*).

Without copying raven-log4j-6.0.0.jar to /usr/local/youtrack/lib, I will get an error like this:

log4j: Class name: [net.kencochrane.raven.log4j.SentryAppender]
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: net.kencochrane.raven.log4j.SentryAppender

but after put it into that lib folder, another error appear:

log4j: Class name: [net.kencochrane.raven.log4j.SentryAppender]
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassCastException: net.kencochrane.raven.log4j.SentryAppender cannot be cast to org.apache.log4j.Appender

Sure, there is no log4j-*.jar in the lib folder:

ls -l /usr/local/youtrack/lib/
total 88
-rw-r--r-- 1 root root 79444 Jan  7 14:13 raven-6.0.0.jar
-rw-r--r-- 1 root root  6798 Jan  7 14:35 raven-log4j-6.0.0.jar

Why and where was it loaded twice?

quanta
  • 3,960
  • 4
  • 40
  • 75

1 Answers1

0

This was resolved on GitHub

One thing worth noting is that you'll still need to include manually add the additional dependencies of both raven (https://github.com/getsentry/raven-java/tree/master/raven#manual-dependency-management) and raven-log4j (https://github.com/getsentry/raven-java/tree/master/raven-log4j#manual-dependency-management) that are not already included by YouTrack (e.g. Jackson, Guava, etc.) since we don't assemble or shade these dependencies with the raven JARs. I don't that think this would be causing the issue, though.

Also, from what I could tell, log4j was also initialized twice by the application (log line: Init web application log4j location: /tmp/youtrack-example/log4j.xml.) The first invocation would always fail with a ClassCastException, while the second would fail to initialize a Raven instance via the RavenFactory (included below.) Both using the automatically registered factory provided by ServiceLoader and explicitly providing a factory yield the same result.

Community
  • 1
  • 1
ehfeng
  • 3,807
  • 4
  • 33
  • 42