Skip to content

AOT causes Logback configuration error when using include #41081

Closed
@michael-wirth

Description

@michael-wirth

Starting an application with AOT and a custom Logback configuration file (logback-spring.xml) with <include> elements can cause configuration errors (specially with file appenders).

The issue is caused by loading the serialized /META-INF/spring/logback-model and processing the model again.

By processing the model all <include> elements will load the configuration files again and attach the parsed submodules to the existing ones loaded from the serialized file.

This might not cause issues for a ConsoleAppender, but will cause a configuration error for FileAppender (same file name).

Breakpoint in ch.qos.logback.core.model.processor.IncludeModelHandler

Screenshot_20240611_210157

Version

Tested with Spring Boot 3.3.1-SNAPSHOT and Java 21

Stacktrace:

java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - 'FileNamePattern' option has the same value "/tmp/spring.log.%d{yyyy-MM-dd}.%i.gz" as that given for appender [FILE] defined earlier.
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collision
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:347)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
 

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration debug="false">
    <springProperty scope="context" name="application" source="spring.application.name"/>
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>
</configuration>

Reproducing the issue:

demo.zip

unzip demo.zip
cd demo
mvn package
java -jar -Dspring.aot.enabled=true target/demo-0.0.1-SNAPSHOT.jar

Metadata

Metadata

Assignees

Labels

theme: aotAn issue related to Ahead-of-time processingtype: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions