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 produces invalid code when referencing an appender from an included file #874

Open
DarkAtra opened this issue Oct 16, 2024 · 1 comment

Comments

@DarkAtra
Copy link

DarkAtra commented Oct 16, 2024

Take the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="logback-console-appender.xml"/>
    <root level="info">
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>

where logback-console-appender.xml defines an appender CONSOLE like so:

<?xml version="1.0" encoding="UTF-8"?>
<included>
    <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>
</included>

Running logback-tyler on the configuration results in:

// package & imports

class TylerConfigurator extends TylerConfiguratorBase implements Configurator {

  @Override
  public Configurator.ExecutionStatus configure(LoggerContext loggerContext) {
    setContext(loggerContext);
    IncludeModel includeModel = new IncludeModel();
    includeModel.setResource(subst("logback-console-appender.xml"));
    IncludeModelHandler includeModelHandler = new IncludeModelHandler(context);
    try {
      Model modelFromIncludedFile = includeModelHandler.buildModelFromIncludedFile(this, includeModel);
      processModelFromIncludedFile(modelFromIncludedFile);
    } catch(ModelHandlerException e) {
      addError("Failed to process IncludeModelHandler", e);
    }
    Logger logger_ROOT = setupLogger("ROOT", "info", null);
    logger_ROOT.addAppender(appenderCONSOLE); // <------------------- does not compile
    return ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY;
  }
}

However, this code does not compile as appenderCONSOLE is not declared anywhere.

Versions:

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

ceki commented Oct 19, 2024

@DarkAtra Thank you for this report.

Please see my comment to issue 873

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