DEV Community

Adam Cervenka
Adam Cervenka

Posted on

Set logback to different level for specific package

If I want to set log level for package com.foo.bar to TRACE I can use a system property logback.configurationFile to define path to logback config.

-Dlogback.configurationFile=/Users/foo/logback.xml
Enter fullscreen mode Exit fullscreen mode

In the Logback config I just need to set a new logger like this:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="com.foo.bar" level="TRACE"/>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>
Enter fullscreen mode Exit fullscreen mode

Discussion (0)