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

[Question] LOGBACK-1731 using variables in path names #746

Open
rPraml opened this issue Nov 30, 2023 · 1 comment
Open

[Question] LOGBACK-1731 using variables in path names #746

rPraml opened this issue Nov 30, 2023 · 1 comment
Assignees

Comments

@rPraml
Copy link

rPraml commented Nov 30, 2023

Hello, we are facing the same issue mentioned in https://jira.qos.ch/browse/LOGBACK-1731 and we hoped, it will be fixed in 1.4.12 (as it is listed in fix-versions)

It seems that there was a change in when we migrated from 1.2 to 1.4
Using scope="system" seems to work in spring.

It seems that there is some logical order problem
As far as I could debug the issue, logback builds a "Model" which represents the complete config (with all included files)
and then, the properties are evolved. So due this order problem, it is not possible to use parameters in include tags. (Note: I'm not very familiar with the architecture in logback, so this is just a guess, what I've ssen in debugger)

When you apply scope="system" - logback puts the value in the system-properties. As spring reloads the logback config at least once, the next run can access the value from the previous run.

Note: we do not really rely on this issue if our use cases could be solved in an other way

Our use cases

1. We want to include an optional properties file (which might not exist)

Preferred solution:

<property file="config/application-local.properties" optional="true"/>

This does not work, because there is no optional support for property and the produced error will prevent spring to run the application

Current solution:

<!-- We define a property, that evaluates to "true", if the file exists -->
<define name="APPLICATION_LOCAL_EXISTS" class="ch.qos.logback.core.property.FileExistsPropertyDefiner" scope="system">
	<path>config/application-local.properties</path>
</define>
<!-- if file exists, we include  application-local.properties-true.inc.xml. 
     If the property file does not exist, no XML is found. 
     This works, because 'include' supports 'optional=true' -->
<include resource="logback/application-local.properties-${APPLICATION_LOCAL_EXISTS}.inc.xml" optional="true"/>

<!-- content of application-local.properties-true.inc.xml -->
<included>
	<property file="config/application-local.properties"/>
</included>

Yes this is a workaround, and I'm sure it was not intended to use it this way, but it did work with 1.2

possible fix
Add 'optional' to 'property'

2. We want to include different appenders.

<property name="consoleAppender" value="${de.foconis.log.console.appender:-CONSOLE}" scope="system"/>
<root>
	<appender-ref ref="${consoleAppender}"/>
</root>

By default we want to use the CONSOLE appender, we have also other appenders like CONSOLE_ANSI, CONSOLE_JSON which formats the output to console in a different way.

If we put all appenders "ready for use" in the logback.xml we get warnings like Appender named [CONSOLE_ANSI] not referenced. Skipping further processing. - so we split them up into a CONSOLE.appender.inc.xml, CONSOLE_ANSI.appender.inc.xml, CONSOLE_JSON.inc.xml and include the dedicated file with

<include optional="true" resource="logback/${consoleAppender}.appender.inc.xml"/>

possible fix
Add 'optionalUse' to 'appender'. If this is set, no warnings are printed, if appender is not in use.

@rPraml
Copy link
Author

rPraml commented Dec 1, 2023

Use case 1 would be solved by #511

@ceki ceki self-assigned this Dec 1, 2023
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

2 participants