[logback-user] class name is displayed incorrectly for java inner classes

Andrew E. Davidson andy_davidson at apple.com
Wed Jul 17 03:03:20 CEST 2013


Hi 

I am using log back-1.0.13. Bellow is the output and sample java code I used to test log back with. noticed that I have an inner class how ever the log output always displays the class name as the outer class. Is there a way to set up log back so that it prints something like outer.inner ??? 

Also has anyone given any thought to defining an XSD file? This would allow my ice (eclipse) to catch a lot of configuration problems for me.

I really appreciate all the hard work everyone has put into this project

thanks in advance

andy

[SLF4JConsoleTest.java] [line   50] [thr main] [class  SLF4JConsoleTest]  [execute()]  Test: INFO level message. 
[SLF4JConsoleTest.java] [line   53] [thr main] [class  SLF4JConsoleTest]  [execute()]  Test: WARN level message. 
[SLF4JConsoleTest.java] [line   56] [thr main] [class  SLF4JConsoleTest]  [execute()]  Test: ERROR level message. 
[SLF4JConsoleTest.java] [line   73] [thr main] [class  SLF4JConsoleTest]  [execute()]  MyInnerClass: INFO level message. 
[SLF4JConsoleTest.java] [line   76] [thr main] [class  SLF4JConsoleTest]  [execute()]  MyInnerClass: WARN level message. 
[SLF4JConsoleTest.java] [line   79] [thr main] [class  SLF4JConsoleTest]  [execute()]  MyInnerClass: ERROR level message. 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<!-- 
	<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
	    < ! - -
		http://logback.qos.ch/manual/filters.html
		http://logback.qos.ch/demo.html 
	    - - >
    	    <Name>FORK_JOIN_MARKER_FILTER</Name>
    	    <Marker>FORK_JOIN_MARKER</Marker>
    	    <OnMismatch>DENY</OnMismatch>
    	    <OnMatch>ACCEPT</OnMatch>
	</turboFilter> 
	-->
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<layout class="ch.qos.logback.classic.PatternLayout">
			<!-- 
			<Pattern>%5p %d{ISO8601} [%t] [%c{0}] [line %L] %m %n</Pattern>
			-->
			<Pattern>[%15file] [line %4L] [thr %4t] [class %17c{0}]  [%method\(\)]  %m %n</Pattern>		
			
		</layout>
	</appender>

	<root level="INFO">
		<appender-ref ref="STDOUT" />
	</root>
</configuration>


public class SLF4JConsoleTest {

    static final Logger LOG = LoggerFactory.getLogger(SLF4JConsoleTest.class);

    /**
     * @param args
     */
    public static void main(String[] args) {
        SLF4JConsoleTest console = new SLF4JConsoleTest();
        console.execute();
    }

    public SLF4JConsoleTest() {
    }

    public void execute() {

        if (LOG.isTraceEnabled()) {
            LOG.trace("Test: TRACE level message.");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Test: DEBUG level message.");
        }
        if (LOG.isInfoEnabled()) {
            LOG.info("Test: INFO level message.");
        }
        if (LOG.isWarnEnabled()) {
            LOG.warn("Test: WARN level message.");
        }
        if (LOG.isErrorEnabled()) {
            LOG.error("Test: ERROR level message.");
        }

        MyInnerClass mic = new MyInnerClass();
        mic.execute();
    }

    public class MyInnerClass {
        public void execute() {

            if (LOG.isTraceEnabled()) {
                LOG.trace("MyInnerClass: TRACE level message.");
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("MyInnerClass: DEBUG level message.");
            }
            if (LOG.isInfoEnabled()) {
                LOG.info("MyInnerClass: INFO level message.");
            }
            if (LOG.isWarnEnabled()) {
                LOG.warn("MyInnerClass: WARN level message.");
            }
            if (LOG.isErrorEnabled()) {
                LOG.error("MyInnerClass: ERROR level message.");
            }
        }
    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130716/18d2ea35/attachment-0001.html>


More information about the Logback-user mailing list