1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[JBoss] JBOSS log4j2-web Log4jServletContextListener in web.xml reading log4jConfiguration...

Discussão em 'StackOverflow' iniciado por Stack, Janeiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    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]

    Continue reading...

Compartilhe esta Página