quarkiverse / quarkus-logging-logback

Quarkus Logback extension
Apache License 2.0
13 stars 14 forks source link

Environment variables in logback.xml not working in native #160

Open krisgerhard opened 11 months ago

krisgerhard commented 11 months ago

Variables in logback.xml are being replaced fine from application.properties but not from environment variables. Works in JVM mode but not in native mode.

krisgerhard commented 11 months ago

I actually observed this in production but managed to reproduce with integration tests.

Reproducer patch 👇 Command used to run tests: ./mvnw verify -Pnative-image -Dquarkus.native.container-build=true

Index: integration-tests/pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
--- a/integration-tests/pom.xml (revision 2640eed0ec467283dc4542da4ff19ed4006d3c31)
+++ b/integration-tests/pom.xml (date 1701419293942)
@@ -58,6 +58,9 @@
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
               <skipTests>${native.surefire.skip}</skipTests>
+              <environmentVariables>
+                <LG_PRE>LOGBACK</LG_PRE>
+              </environmentVariables>
             </configuration>
           </plugin>
           <plugin>
@@ -74,6 +77,9 @@
                     <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                     <maven.home>${maven.home}</maven.home>
                   </systemPropertyVariables>
+                  <environmentVariables>
+                    <LG_PRE>LOGBACK</LG_PRE>
+                  </environmentVariables>
                 </configuration>
               </execution>
             </executions>
Index: integration-tests/src/main/resources/logback.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/integration-tests/src/main/resources/logback.xml b/integration-tests/src/main/resources/logback.xml
--- a/integration-tests/src/main/resources/logback.xml  (revision 2640eed0ec467283dc4542da4ff19ed4006d3c31)
+++ b/integration-tests/src/main/resources/logback.xml  (date 1701287842133)
@@ -4,11 +4,11 @@
         <file>target/tests.log</file>
         <append>false</append>
         <encoder>
-            <pattern>LOGBACK- %-5level %msg %n</pattern>
+            <pattern>${lg.pre}- %-5level %msg%n</pattern>
         </encoder>
     </appender>

     <root level="trace">
         <appender-ref ref="FILE" />
     </root>
-</configuration>
\ No newline at end of file
+</configuration>
krisgerhard commented 11 months ago

Could be related to https://github.com/quarkusio/quarkus/issues/37273

krisgerhard commented 11 months ago

Or https://github.com/quarkusio/quarkus/issues/37444

krisgerhard commented 11 months ago

@stuartwdouglas Is there a way to set these values in runtime in native mode using env variables? As i understand config expansion is done during static initialization :/

stuartwdouglas commented 11 months ago

I think we would need to move logback initialization from static init to runtime init. I am not sure what the effects of such a change would be without trying it out.

krisgerhard commented 10 months ago

@stuartwdouglas Have you found time for this issue? :)

krisgerhard commented 10 months ago

Workaround is to supply this environment variable during build time.

In order to do it for container build, you need to pass quarkus.native.additional-build-args

  1. export QUARKUS_NATIVE_ADDITIONAL_BUILD_ARGS="-J-Dlg.pre=LOGBACK"
  2. quarkus.native.additional-build-args=-J-Dlg.pre=LOGBACK in application.properties etc.