Tutorial :How do I use logback-access in combination with Tomcat 5.5?



Question:

I've got several Web apps running on a Tomcat 5.5 server, and I'm working on improving/updating the overall logging system used throughout the system. I already had some success with logback-classic. However, when I try to use logback-access (i.e. access the lbAccessStatus servlet), I get this exception:

  exception    javax.servlet.ServletException:    Wrapper cannot find servlet class      ch.qos.logback.access.ViewStatusMessagesServlet    or a class it depends on    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)  ...    root cause    java.lang.ClassNotFoundException:    ch.qos.logback.access.ViewStatusMessagesServlet    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)  ...  

I have everything set up according to the docs:

    common/lib:      logback-classic-0.9.15.jar      logback-core-0.9.15.jar    server/lib:      logback-access-0.9.15.jar  

Moving around the libraries doesn't seem to help. logback-classic seems to work fine, it's just logback-access that causes problems.


Solution:1

I've got it working. With maven and logback-classic the jars end in WEB-INF/lib and it works well. I've seen the same error only when deploying old version of my WAR.

excerpt of dependencies section of my pom.xml

<dependency>    <groupId>org.slf4j</groupId>    <artifactId>slf4j-api</artifactId>    <version>${slf4j.version}</version>  </dependency>  <dependency>      <groupId>ch.qos.logback</groupId>      <artifactId>logback-classic</artifactId>      <version>0.9.21</version>  </dependency>  

... and relevant part of my web.xml:

  <servlet>      <servlet-name>LogbackViewStatusMessages</servlet-name>      <servlet-class>ch.qos.logback.classic.ViewStatusMessagesServlet</servlet-class>    </servlet>    <!-- see http://localhost:8080/oam-portal-portlets/logs -->    <servlet-mapping>      <servlet-name>LogbackViewStatusMessages</servlet-name>      <url-pattern>/logback</url-pattern>    </servlet-mapping>  


Solution:2

I haven't used logback-access with tomcat, yet. I only used it with jetty...

I'd suggest to try the following setup, though:

common/lib:    logback-access-0.9.15.jar    logback-classic-0.9.15.jar    logback-core-0.9.15.jar  server/lib:    logback-access-0.9.15.jar    logback-core-0.9.15.jar  

logback-access has logback-core as a dependency. Since you use it both in the server (the Valve) and in your webapp (the ViewStatusMessagesServlet) you should add it to both classpaths.

You could (and should?) also add logback-access, logback-classic and logback-core to your webapp classpath instead of adding it to common/lib, making it available to all webapps.

Hope that helps.


Solution:3

If you put logback-access in common/lib too, so all the jars are there, it should be available everywhere. Have you tried that?

Also logging has been reworked in Tomcat 6. Is upgrading a possibility?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »