jdaugherty commented on issue #12874: URL: https://github.com/apache/grails-core/issues/12874#issuecomment-4379829486
Root Cause (Two-part)
1. Logback can't parse YAML natively.
The user's <property resource="application.yml" /> directive tells Logback
to load a classpath resource as a Java .properties file. Logback has zero YAML
support — it reads key=value format only. So ${info.app.name} resolves to
info.app.name_IS_UNDEFINED in all environments, not just production. The
fact that it seems to work in development is likely coincidence (e.g., the JAR
name matches, or the user isn't looking closely at dev logs).
2. Timing: logback initializes before Spring.
Even if the YAML were parseable, Spring Boot initializes the logging
subsystem before it loads application.yml into the Environment. There's no code
in Grails (ExternalConfigRunListener, GrailsApplicationPostProcessor, etc.)
that
feeds application properties into Logback at startup.
The Correct Fix (for users)
Spring Boot's Logback extension provides <springProperty> specifically for
this. In a logback-spring.xml (not logback.xml):
<springProperty scope="local" name="appName" source="info.app.name"
defaultValue="myapp"/>
<appender name="FILE" class="...">
<file>${appName}/logs/${appName}.log</file>
...
</appender>
<springProperty> hooks into the Spring Environment after it's been
populated, which is exactly when logback-spring.xml is processed. This works in
both dev and production.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
