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

logback-tyler does not support Spring Boot expressions in if conditions #875

Open
DarkAtra opened this issue Oct 16, 2024 · 3 comments
Open

Comments

@DarkAtra
Copy link

DarkAtra commented Oct 16, 2024

Take the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <if condition='${consoleEnabled}'>
        <then>
            <root level="info">
                <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
                    <encoder>
                        <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %5level %logger{0} [%t] - %msg%n</pattern>
                    </encoder>
                </appender>
            </root>
        </then>
    </if>
</configuration>

The logback-tyler output would be:

// package & imports

class TylerConfigurator extends TylerConfiguratorBase implements Configurator {

  @Override
  public Configurator.ExecutionStatus configure(LoggerContext loggerContext) {
    setContext(loggerContext);
    if(${consoleEnabled}) { // <---------------------------- this does not compile
      Logger logger_ROOT = setupLogger("ROOT", "info", null);
      Appender appenderCONSOLE = setupAppenderCONSOLE();
    }
    return ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY;
  }

  Appender setupAppenderCONSOLE() {
    ConsoleAppender appenderCONSOLE = new ConsoleAppender();
    appenderCONSOLE.setContext(context);
    appenderCONSOLE.setName("CONSOLE");

    // Configure component of type PatternLayoutEncoder
    PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
    patternLayoutEncoder.setContext(context);
    patternLayoutEncoder.setPattern("%d{YYYY-MM-dd HH:mm:ss.SSS} %5level %logger{0} [%t] - %msg%n");
    patternLayoutEncoder.setParent(appenderCONSOLE);
    patternLayoutEncoder.start();
    // Inject component of type PatternLayoutEncoder into parent
    appenderCONSOLE.setEncoder(patternLayoutEncoder);

    appenderCONSOLE.start();
    return appenderCONSOLE;
  }
}

As you can see, the if condition that uses a spring expression is not converted correctly - probably because logback-tyler doesn't know anything about spring.

Is there anything that spring-boot could do to participate in the conversion for spring specific features?

Versions:

spring-boot: 3.3.4
logback-classic: 1.5.11
logback-tyler: 0.9
@ceki
Copy link
Member

ceki commented Oct 19, 2024

It think adding the appropriate spring-boot code should be feasible.

@DarkAtra
Copy link
Author

DarkAtra commented Oct 25, 2024

It think adding the appropriate spring-boot code should be feasible.

Do you mean adding it directly to logback-tyler or to have a spring specific version of logback-tyler as a separate project?
If it's the later, i guess addModelHandlerAssociations needs to be non private.

@ceki
Copy link
Member

ceki commented Oct 25, 2024

@DarkAtra We also need a subclass of JoranConfigurator which can produce SpringPropertyModel instances from <springProperty> elements. This is certainly feasible but would require a little work.

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