I am trying to configure logging into a file in a Spring Boot native image. According to this answer, Logback should be configurable with xml.
So I created the following logback-spring.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="/springframework/boot/logging/logback/defaults.xml" />
<include resource="/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<springProfile name="native">
<property name="LOG_FILE" value="log/my-app.log"/>
<include resource="/springframework/boot/logging/logback/file-appender.xml" />
<root>
<appender-ref ref="FILE" />
</root>
</springProfile>
</configuration>
When I build the image with mvn -Pnative spring-boot:build-image
and run it with docker run --rm -v /tmp/log:/workspace/log docker.io/library/my-app:0.0.1
, the log file doesn't created.
The logging config works correctly when running as a normal java app.