Moocar / logback-gelf

Logback plugin to send GELF messages to graylog2 server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GelfAppender class not found in tomcat

Moocar opened this issue · comments

I downloaded logback-gelf-0.9.6-jar-with-dependencies.jar and put it in my tomcat's shared lib folder, and created a symlink for "logback-gelf.jar".

I then added an appender as per the logback-gelf readme, and restarted tomcat.

Once it did restart, instead of getting logs sent to my graylog2 server, I started getting stack traces in catalina.out.

What am I missing or doing wrong?

Thank you.

My appender is:

<appender name="GELF" class="me.moocar.logbackgelf.GelfAppender">
  <facility>${contextName}</facility>
    <graylog2ServerHost>MyGraylog2Server</graylog2ServerHost>
    <graylog2ServerPort>12201</graylog2ServerPort>
    <useLoggerName>true</useLoggerName>
    <useThreadName>true</useThreadName>
    <graylog2ServerVersion>0.9.6</graylog2ServerVersion>
    <chunkThreshold>1000</chunkThreshold>
</appender>

Stacktrace snippets follow:

09:29:34,049 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [me.moocar.logbackgelf.GelfAppender]
09:29:34,049 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [me.moocar.logbackgelf.GelfAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type me.moocar.logbackgelf.GelfAppender
at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type me.moocar.logbackgelf.GelfAppender

Caused by: java.lang.ClassNotFoundException: me.moocar.logbackgelf.GelfAppender

at ... 57 common frames omitted
09:29:34,050 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@19:68 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type me.moocar.logbackgelf.GelfAppender
at ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type me.moocar.logbackgelf.GelfAppender

Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type me.moocar.logbackgelf.GelfAppender

at ... 55 common frames omitted
Caused by: java.lang.ClassNotFoundException: me.moocar.logbackgelf.GelfAppender

at ... 57 common frames omitted

The issue is that logback can't find me.moocar.logback.GelfAppender, which means it isn't on the classpath correctly. I'm not a tomcat guy so I'm not sure why it's not picking up the jar correctly. Do you have other jars in the shared libs folder? Can you verify that other libraries placed in that directory are being picked up?

This actualyl wound up being a problem with my understanding of logback (which was very limited).

I had neglected to alter this section:

But once I did, it worked.

This can be closed as it was user error not a program error.

I have exactly the same problem, I'd love to know what llowder changed to get it to work! We've got other libs loading from our tomcat lib dir fine, one which is an extended log valve.

I've even tried copying in the exact jar files I've had working with the http://logback.qos.ch/demo.html webapp to no avail..

Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type me.moocar.logbackgelf.GelfAppender
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:32)
at at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:54)
at ... 39 common frames omitted
Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/core/AppenderBase

I've now built a new version using mvn clean install assembly:single and copied that over to the tomcat lib dir. Which has these libs:-

annotations-api.jar ecj-4.2.1.jar tomcat-api.jar
antlr-2.7.2.jar el-api.jar tomcat-coyote.jar
catalina-ant.jar EscapingAccessLogValve-1.3.jar tomcat-dbcp.jar
catalina-ha.jar gelfj-0.9.1.jar tomcat-i18n-es.jar
catalina.jar janino-2.4.3.jar tomcat-i18n-fr.jar
catalina-tribes.jar jasper-el.jar tomcat-i18n-ja.jar
commons-beanutils-1.7.0.jar jasper.jar tomcat-jdbc.jar
commons-collections-2.1.jar jsp-api.jar tomcat-util.jar
commons-digester-1.6.jar logback-gelf-0.9.6p3-SNAPSHOT-jar-with-dependencies.jar xalan-2.5.1.jar
commons-fileupload-1.0.jar oro-2.0.7.jar xml-apis-1.0.b2.jar
commons-logging-1.1.1.jar servlet-api.jar
commons-validator-1.1.4.jar struts-1.2.9.jar

My webapp has these libs in it:-

aopalliance-1.0.jar httpcore-4.1.2.jar semantico-util-querymap-1.5.jar spring-context-3.1.2.RELEASE.jar
commons-codec-1.6.jar icu4j-3.4.4.jar semantico-util-status-1.1.jar spring-context-support-3.1.2.RELEASE.jar
commons-lang-2.1.jar jasypt-1.4.1.jar sgk-2.25.jar spring-core-3.1.2.RELEASE.jar
commons-logging-1.1.1.jar jcl-over-slf4j-1.6.4.jar slf4j-api-1.6.4.jar spring-expression-3.1.2.RELEASE.jar
freemarker-2.3.19.jar jyaml-1.3.jar spring-aop-3.1.2.RELEASE.jar spring-web-3.1.2.RELEASE.jar
guava-13.0.jar logback-classic-1.0.0.jar spring-asm-3.1.2.RELEASE.jar spring-webmvc-3.1.2.RELEASE.jar
httpclient-4.1.2.jar logback-core-1.0.0.jar spring-beans-3.1.2.RELEASE.jar

I'm now getting a different error:-

ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [me.moocar.logbackgelf.GelfAppender]. ch.qos.logback.core.util.IncompatibleClassException
at ch.qos.logback.core.util.IncompatibleClassException

and this warning:-

WARNING: [SetContextPropertiesRule]{Context} Setting property 'debug' to '0' did not find a matching property.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/semantico/sre/tctest/apache-tomcat-7.0.34/lib/logback-gelf-0.9.6p3-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/semantico/slot/sgk_SACHA/1/sitecode/webapps/ROOT/WEB-INF/lib/logback-classic-1.0.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

I'm starting to think that maybe we should just add the jars into the app.

Oh well, pulling out the jars from the app and just leaving the gelf jar worked. I don't like this solution though as I think it's dependency hell in waiting, I'll just put gelf into the app.