Search code examples
javalogback

Print archive (jar) the log is coming from in logback


I have some descrepency between class implementations on a Tomcat server and a Websphere server. Is there a way in logback to display the jar and version next in every log? So the log would look like this:

DEBUG | 2015-01-22 16:13:49.252 [Default Executor-thread-7] ApplicationName org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo - Canonicalized SignedInfo: [wss4j.jar 1.6.17]

My current pattern is this:

<pattern>%-5level | %date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %contextName %logger - %message%n</pattern>

My POM:

<dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.30</version>
            <type>jar</type>
            <scope>runtime</scope>
        </dependency>

Solution

  • I would suggest examining the full classpath of the Java process, you can simply use

    jinfo [pid]
    

    You'll get plenty of output, including java.class.path with all the jars and what order they are in

    It's been a fairly common problem with large app servers (WebSphere, etc.) that have some other version of a library that shows up on the classpath first that you may not be expecting