When using the structured log feature of Spring Boot 3.4 within a native image, custom log fields are not present.
In application.properties:
logging.structured.format.console=ecs
logging.structured.ecs.service.environment=test
The service.environment property is not present in the outputted logs.
Reproduction repo: https://github.com/Jul13nT/spring-native-structured-logging
First, run the application with spring-boot:run ./mvnw spring-boot:run
The produced log is:
{"@timestamp":"2025-01-16T14:59:06.731337409Z","log.level":"INFO","process.pid":211713,"process.thread.name":"main","service.name":"simple","service.environment":"test","log.logger":"com.test.SimpleApplication","message":"Started SimpleApplication in 1.278 seconds (process running for 1.625)","ecs.version":"8.11"}
"service.environment":"test" is present.
Then, run the application in native image:
./mvnw spring-boot:build-image -Pnative
docker run --rm -p 8080:8080 spring-native-structured-logging:0.0.1-SNAPSHOT
The log is now:
{"@timestamp":"2025-01-16T15:04:36.133516Z","log.level":"INFO","process.pid":1,"process.thread.name":"main","service.name":"simple","log.logger":"com.test.SimpleApplication","message":"Started SimpleApplication in 0.069 seconds (process running for 0.075)","ecs.version":"8.11"}
The field service.environment is missing.
Comment From: wilkinsona
Thanks for the report, @Jul13nT. I suspect we're missing reflection hints that allow the binding of logging.structured.ecs properties to org.springframework.boot.logging.structured.ElasticCommonSchemaProperties.
We may have a similar problems with binding logging.structured.json to StructuredLoggingJsonProperties and logging.structured.gelf to GraylogExtendedLogFormatProperties.
Comment From: nosan
If you haven’t started working on it yet, @wilkinsona, would it be okay if I took it on?
Comment From: wilkinsona
Yes please, @nosan, that'd be great.
Comment From: philwebb
Closing in favor of PR #43862. Thanks @nosan!