4

I have the following the logback.xml file

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<logger name="my.package">
    <level value="TRACE"/>
</logger>

<logger name="org.springframework.web">
    <level value="DEBUG"/>
</logger>

<root>
    <priority value="debug"/>
    <appender-ref ref="STDOUT"/>
</root>

When I run the application, in console I see messages which was invoked like this:

LOGGER.error("error ");

from classes inside my.package
I don't see messages from spring.

What do I wrong?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

2 Answers2

4

By default Spring logs to Apache Commons Logging. To switch it to logback exclude Commons Logging

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.3.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

and add bridge to Logback

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.12</version>
    </dependency>
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1

Spring uses commons-logging, so you need to use the jcl-over-slf4j bridge to make spring think it's using jcl.

You'll need to exclude commons-logging from the spring dependencies in your pom, and include the jcl-over-slf4j.

More information: Bridging Legacy APIs

Kayaman
  • 72,141
  • 5
  • 83
  • 121