wassim
wassim

Reputation: 377

JBOSS log4j2-web Log4jServletContextListener in web.xml reading log4jConfiguration without environment variable substitution

After a spring upgrade from 4.x to 5.x, we had to move from org.springframework.web.util.Log4jConfigListener to log4j2-web org.apache.logging.log4j.web.Log4jServletContextListener and from log4jConfigLocation to log4jConfiguration.

The log4j2.xml file is configured as below

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>file:///${env:SOME_ENV_VARIABLE}/ws/log4j2.xml</param-value>
    </context-param>

However, when the war is deployed on JBOS-EAP 7.3, the environment variable is not being read correctly as shown below (the same happens when configuring it with env as <param-value>file:///${SOME_ENV_VARIABLE}/ws/log4j2.xml</param-value>) and the log4j2.xml file is not being read

14:00:07,834 INFO  [stdout] (ServerService Thread Pool -- 202) 2025-01-17T11:00:07.834Z ServerService Thread Pool -- 202 DEBUG getConfigURI found [file:///$%7Benv:SOME_ENV_VARIABLE%7D/ws/log4j2.xml] in servletContext at [file:///${env:SOME_ENV_VARIABLE}/ws/log4j2.xml]

The previous configuration with spring 4.x was

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>file:///${SOME_ENV_VARIABLE}/ws/log4j2.xml</param-value>
    </context-param>

and from the log4j2 logs i can see, the env variable is being substituted before the log4j2 initialization and log4j2 is able to read the file and use it.

DEBUG getConfigURI found [file:///C:/test/ws/log4j2.xml] in servletContext at [file:///C:\test\/ws/log4j2.xml]

UPDATE The same seems to work fine with JBOSS EAP 7.4 while the issue is there with JBOSS EAP 7.3

Upvotes: 0

Views: 40

Answers (0)

Related Questions