Wednesday, January 14, 2015

Conditional appender in Logback

To use a conditional appender in Logback,

use an 'if' element in logback.xml as follows:

    <root level="INFO">
        <if condition='!property("spring.profiles.active").contains("production")'>
            <then>
                <appender-ref ref="CONSOLE" />
            </then>
        </if>
        <appender-ref ref="DEBUG_LOG_APPENDER" />
    </root>

To use conditional processing,

you should add Janino dependency to build.gradle as follows:

compile("org.codehaus.janino:janino:2.7.7")

References:
http://logback.qos.ch/manual/configuration.html
http://logback.qos.ch/setup.html#janino

No comments:

Post a Comment