[logback-user] Problem with logback-access and logback-classic within Tomcat

Simon Schabel me at simonschabel.com
Tue Mar 26 22:13:13 CET 2019


Hello,

I tried to centralize logging in our docker environment by using logback 
as default logging framework. The idea is to use logback in our core 
application which compiles to a *.war file which is deployed in an 
Apache Tomcat v8.5.

We now use Docker and I want to get a logging setup in our swarm like that:




Our own *.war file is already successfully logging to STDOUT with 
logback and the logstash-logback-encoder. After I deployed the war to 
Tomcat running within a Docker container I realized that more 
information coming from Tomcat is logged via STDOUT and this is not in 
JSON format.

I also read about logback-access and how to use it in Tomcat so I first 
added logback-access to the classpath of Tomcat and added a 
logback-access.xml config file as well. In the server.xml I added <Valve 
className="ch.qos.logback.access.tomcat.LogbackValve"/>. The server.xml 
looks like:

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
     <!--<Listener 
className="org.apache.catalina.startup.VersionLoggerListener"/>-->
     <Listener className="org.apache.catalina.core.AprLifecycleListener" 
SSLEngine="on"/>
     <Listener 
className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
     <Listener 
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
     <Listener 
className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
     <GlobalNamingResources>
         <Resource name="UserDatabase" auth="Container"
                   type="org.apache.catalina.UserDatabase"
                   description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                   pathname="conf/tomcat-users.xml"/>
     </GlobalNamingResources>
     <Service name="Catalina">
         <Connector port="8080" protocol="HTTP/1.1"
                    connectionTimeout="20000"
                    redirectPort="8443"/>
         <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
         <Engine name="Catalina" defaultHost="localhost">
             <Realm className="org.apache.catalina.realm.LockOutRealm">
                 <Realm 
className="org.apache.catalina.realm.UserDatabaseRealm" 
resourceName="UserDatabase"/>
             </Realm>
             <Host name="localhost" appBase="webapps" unpackWARs="true" 
autoDeploy="true">
                 <Valve 
className="ch.qos.logback.access.tomcat.LogbackValve" />
             </Host>
         </Engine>
     </Service>
</Server>

Running our war like this works.

Now I wanted to make Tomcat to use logback as default logging framework 
as well and integrated
ADD logback-core-1.2.3.jar /usr/local/tomcat/lib/
ADD logback-classic-1.2.3.jar /usr/local/tomcat/lib/
ADD logstash-logback-encoder-5.3.jar /usr/local/tomcat/lib/
ADD jackson-databind-2.9.8.jar /usr/local/tomcat/lib/
ADD jul-to-slf4j-1.7.26.jar /usr/local/tomcat/lib/
ADD slf4j-api-1.7.26.jar /usr/local/tomcat/lib/
ADD jackson-core-2.9.8.jar /usr/local/tomcat/lib/
ADD jackson-annotations-2.9.8.jar /usr/local/tomcat/lib/

to the lib folder as well as to the classpath via setenv.sh:

export 
CLASSPATH="$CATALINA_HOME/lib/jul-to-slf4j-1.7.26.jar:$CATALINA_HOME/lib/slf4j-api-1.7.26.jar:$CATALINA_HOME/lib/logback-classic-1.2.3.jar:$CATALINA_HOME/lib/logstash-logback-encoder-5.3.jar:$CATALINA_HOME/lib/jackson-databind-2.9.8.jar:$CATALINA_HOME/lib/jackson-core-2.9.8.jar:$CATALINA_HOME/lib/jackson-annotations-2.9.8.jar:$CATALINA_HOME/lib/logback-access-1.2.3.jar:$CATALINA_HOME/lib/logback-core-1.2.3.jar:$CATALINA_HOME/conf/logback/"


I also added a proper logback.xml for Tomcat.


Unfortunately in this situation the Tomcat server process is not 
starting up correctly as the following error occurs:

java.lang.NoClassDefFoundError: org/apache/catalina/Lifecycle
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
         at 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
         at 
org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:116)
         at 
org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1250)
         at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
         at 
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
         at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
         at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
         at 
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
         at 
org.apache.tomcat.util.digester.Digester.parse(Digester.java:1518)
         at org.apache.catalina.startup.Catalina.load(Catalina.java:611)
         at org.apache.catalina.startup.Catalina.load(Catalina.java:662)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
         at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.lang.reflect.Method.invoke(Method.java:498)
         at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:309)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.Lifecycle
         at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
         ... 35 common frames omitted
java.lang.NoClassDefFoundError: org/apache/catalina/Lifecycle
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
         at 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
         at 
org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:116)
         at 
org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1250)
         at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
         at 
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
         at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
         at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
         at 
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
         at 
org.apache.tomcat.util.digester.Digester.parse(Digester.java:1518)
         at org.apache.catalina.startup.Catalina.load(Catalina.java:611)
         at org.apache.catalina.startup.Catalina.load(Catalina.java:662)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
         at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.lang.reflect.Method.invoke(Method.java:498)
         at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:309)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.Lifecycle
         at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
         ... 35 more


Now if I commend out the line <Valve 
className="ch.qos.logback.access.tomcat.LogbackValve" /> from the 
server.xml the startup is running fine and Tomcat logs via 
logback-classic - but logback-access is not used.


I found a question on stackoverflow.com where people seem to have the 
same problem but no solution is provided:

https://stackoverflow.com/questions/32134974/added-logback-to-tomcat-got-java-lang-classnotfoundexception-org-apache-catali




Does anyone has a hint for me what is going wrong?

Best
Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20190326/5b5bca68/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kopedpbjihpheieb.png
Type: image/png
Size: 26971 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20190326/5b5bca68/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mdahljlacdedoalg.png
Type: image/png
Size: 49672 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20190326/5b5bca68/attachment-0003.png>


More information about the logback-user mailing list