Search code examples
springlogback

Logback not logging SQL statements


I am trying to get logback to log SQL statements generated from iBatis.

Here is what I have

pom.xml

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
        </layout>
    </appender>

    <logger name="java.sql" level="TRACE">
        <appender-ref ref="STDOUT" />
    </logger>

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

This is what I see when I start my app

15:25:49,860 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
15:25:49,860 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
15:25:49,860 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/user/code/myapp/target/classes/logback.xml]
15:25:49,980 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:25:49,983 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:25:50,004 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
15:25:50,107 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
15:25:50,107 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
15:25:50,107 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
15:25:50,110 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql] to TRACE
15:25:50,110 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[java.sql]
15:25:50,112 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:25:50,112 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
15:25:50,112 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:25:50,114 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@659f087 - Registering current configuration as safe fallback point

This is a Struts 1.x / Spring 3.x web app using iBatis. I am trying to upgrade the logging from log4j 1.x. SQL was logging fine before with a very similar log4j config, but doesnt seem to be working with logback.


Solution

  • The other projects use Log4J (IIRC) which has nothing to do with Logback. Logback configs would be completely ignored since they're not using Logback.

    You'd need a bright like log4j-over-slf4j:

    https://www.slf4j.org/legacy.html