qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
2.97k stars 1.28k forks source link

logback-classic 1.5.5 breaks conditional logger from included xml #805

Closed johanmast closed 4 months ago

johanmast commented 4 months ago

After updating to logback-classic 1.5.5, conditional logger elements from included files break.

The conditional logger is ignored and the following line is logged:

WARN in ch.qos.logback.core.model.processor.ImplicitModelHandler - Ignoring unknown property [logger] in [ch.qos.logback.classic.LoggerContext]

Reproduction

logback.xml:

<configuration>
    <include resource="logback-include.xml"/>

    <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>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>

</configuration>

logback-include.xml:

<included>
    <appender name="file" class="ch.qos.logback.core.FileAppender">
        <file>filelogging.log</file>
        <append>true</append>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <if condition='true'>
        <then>
            <logger name="custom" additivity="false" level="info">
                <appender-ref ref="file"/>
            </logger>
        </then>
    </if>
</included>

Expected behaviour:

LoggerFactory.getLogger("root").info("test1"); //logged to console
LoggerFactory.getLogger("custom").info("test2"); //logged to file

Actual behaviour:

LoggerFactory.getLogger("root").info("test1"); //logged to console
LoggerFactory.getLogger("custom").info("test2"); //logged to console

The expected behaviour still works with version 1.5.4.

fupgang commented 4 months ago

We also recognized broken logging configurations after upgrading logback from 1.5.4 to 1.5.5. In our case there are <springProperty> tags in an included Snippet that are not handled correctly anymore.

Version 1.5.5 migrated IncludeAction to IncludeModelHandler (af92be47a940393e11decab0a7ee4cb802d2b5e8) , which seems to break something.

ceki commented 4 months ago

@fupgang File inclusion code moved from IncludeAction to IncludeModelHandler. This changes the moment in time file inclusion occurs.

<springProperty> might rely on some logback internals in IncludeAction which have changed. This a different issue than what @johanmast reports above.

@fupgang Please create a separate issue.

ceki commented 4 months ago

@johanmast I will add a test case for the situation you describe which is a very special case, i.e a conditional within an inclusion...

I am correct to assume that you are also using logback-core 1.5.5?

johanmast commented 4 months ago

Hi @ceki,

Thank you. Yes, dependencies used are:

ceki commented 4 months ago

Created https://jira.qos.ch/browse/LOGBACK-1768 for tracking.

ceki commented 4 months ago

Fixed in commit 759fc25ee38435

ceki commented 4 months ago

logback version 1.5.6 was released earlier today.

johanmast commented 4 months ago

Thank you @ceki, I can confirm that it works again when using version 1.5.6