grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Logback - logback.xml, reading properties from application.yml fails ONLY in production

Open gsartori opened this issue 2 years ago • 1 comments

Expected Behavior

Running the app a folder sould be created like the follow:

appname/logs/appname.log

The following configuration works when running the app in DEV on IntelliJ IDEA but fails when the app is run as .jar in PROD:

-- logback.xml

<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <charset>UTF-8</charset>
        <pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex</pattern>
    </encoder>
</appender>

<property resource="application.yml" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${info.app.name}/logs/${info.app.name}.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        <fileNamePattern>${info.app.name}/logs/archive/${info.app.name}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
        <cleanHistoryOnStart>true</cleanHistoryOnStart>
        <maxHistory>10</maxHistory>
        <maxFileSize>10MB</maxFileSize>
        <totalSizeCap>100GB</totalSizeCap>
    </rollingPolicy>

    <encoder>
        <charset>UTF-8</charset>
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%15.15t] %-40.40logger{39} : %m%n%wex</pattern>
    </encoder>
</appender>

<root level="ERROR">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
</root>

Actual Behaviour

The following folder structure gets created in PROD (running the app as jar):

info.app.name_IS_UNDEFINED/logs/info.app.name_IS_UNDEFINED.log

Steps To Reproduce

  1. grails create-app test
  2. copy the attached logback.xml.zip into test/grails-app/conf/
  3. ./gradlew bootJar
  4. cd test/build/libs
  5. java -jar test-0.1.jar

Environment Information

openjdk version "17.0.5" 2022-10-18 OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08) OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing) Groovy Version: 4.0.8 JVM: 17.0.5 Vendor: GraalVM Community OS: Mac OS X Grails Version: 5.2.5 JVM Version: 17.0.5

Example Application

No response

Version

5.2.5

gsartori avatar Feb 14 '23 10:02 gsartori

Adding to the issue, it happens only to the properies expanded by grails, like the following:

info:
    app:
        name: '@info.app.name@'
        version: '@info.app.version@'
        grailsVersion: '@info.app.grailsVersion@'

it works in PROD when configured as:

info.app.name: my-app-name

gsartori avatar Feb 14 '23 10:02 gsartori