Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of <include> with properties changes form 1.2.x to 1.3.x #733

Open
fupgang opened this issue Nov 21, 2023 · 0 comments
Open

Handling of <include> with properties changes form 1.2.x to 1.3.x #733

fupgang opened this issue Nov 21, 2023 · 0 comments

Comments

@fupgang
Copy link

fupgang commented Nov 21, 2023

Hello everyone,

we just realized that logback behaves differently when handling the inclusion of files that use properties.
This different behavior was introduced with version 1.3.0 and its changes to the configuration implementation.
I'm not sure whether this is actually a bug. Perhaps we relied on something that was never intended to work.

Our usecase

We want to include a configuration snippet multiple times and use properties to slightly change the snippet every time.

A very simple example is an appender definition with a name derived from a property:

<included>
    <appender name="${name}" class="ch.qos.logback.core.ConsoleAppender">
        <!-- ... -->
    </appender>
</included>

Now we want to include this snippet to create appenders with different names:

    <property name="name" value="A" />
    <include resource="snippet.xml"/>

    <property name="name" value="B" />
    <include resource="snippet.xml"/>

Thus, we want to pass parameters to the snippet.

Version 1.2.x

This works fine with version 1.2.12.
Here's the status log:

09:45:03,179 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@566776ad - Adding [file://snippet.xml] to configuration watch list.
09:45:03,180 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:45:03,182 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [A]
09:45:03,203 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@566776ad - Adding [file://snippet.xml] to configuration watch list.
09:45:03,205 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:45:03,205 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [B]

Version 1.3.x

This doesn't work anymore since version 1.3.0. It doesn't work with 1.4.11 neither.
The properties value is always B (as seen by the included snippets).

10:12:35,409 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@7b49cea0 - Adding [file:///snippet.xml] to configuration watch list.
10:12:35,413 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@7b49cea0 - Adding [file:///snippet.xml] to configuration watch list.
10:12:35,458 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [B]
10:12:35,458 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
10:12:35,476 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [B]
10:12:35,477 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]

In our real world use case the application does not start anymore, since logback detects the same file name pattern to be used multiple times.

Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.

The file name pattern is defined by a property. The file appenders are included with a snippet.

Related issues

There is an open feature request to support passing of parameters to included snippets in a different way: https://jira.qos.ch/browse/LOGBACK-1104
If this is not considered a bug, I vote for this feature request.

https://jira.qos.ch/browse/LOGBACK-1760 might be related, even though the variable is used in the <include> tag not in the included snippet.
Since this ticket states 1.4.12 as fix version, I tried our use case with the 1.4.12-SNAPSHOT but it doesn't work.

Thank you for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant