Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring logging threshold not being set by logback

I am working with Spring (Core/Security/ldap and more), and logback. But for some reason spring does not receive the loggin threshhold set in the logback XML I can see that as well when i debug springs source code and i see that the

final boolean debug = logger.isDebugEnabled();

Is false

As well i would like to mention (I don't know if it has any relevance) that the logger that spring uses is:

org.apache.commons.logging.LogFactory
org.apache.commons.logging.Log

And not SLF4j like i use

So how am i supposed to enable the debug level and bring the logs into my SLF4J configuration..

Thanks

like image 262
Gleeb Avatar asked Dec 11 '22 08:12

Gleeb


1 Answers

Spring by default uses Apache's Jakarta Commons Logging library. You need to disable it and instead use the slf4j bridge. You should have the following (among others)

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- Logging -->
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>${logback.version}</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${slf4j.version}</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>

Then your logback.xml or other configuration can set the log level. For example,

<logger name="org.springframework" level="info" additivity="false">
    <appender-ref ref="STDOUT" />
</logger>
like image 97
Sotirios Delimanolis Avatar answered Dec 13 '22 23:12

Sotirios Delimanolis