Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krisgerhard opened this issue Dec 1, 2023 · 7 comments
Open

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

krisgerhard opened this issue Dec 1, 2023 · 7 comments

Comments

@krisgerhard
Copy link

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
Copy link
Author

krisgerhard commented Dec 1, 2023

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
Copy link
Author

Could be related to quarkusio/quarkus#37273

@krisgerhard
Copy link
Author

Or quarkusio/quarkus#37444

@krisgerhard
Copy link
Author

@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
Copy link
Contributor

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
Copy link
Author

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

@krisgerhard
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants