log4j2 - configuration file found

百般思念 提交于 2019-12-11 14:19:43

问题


I am using servlet 2.5 and i followed the instructions to set up the listeners and filters, but still my webapp complains that the configuration file cannot be found. My listener, context param,filter and filter mappings are all defined as the first values in their respective locations in my web.xml. I made sure log4j-web-2.2.jar is in my classpath as well. Are there other options to load them from a spring bean? I would like to load a different config file based on a value in catalina.properties. Can somebody please advice?

 <listener>
    <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>classpath:*${sys:log4j2.xml.name}</param-value>

<filter>
    <filter-name>log4jServletFilter</filter-name>
    <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>log4jServletFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>

</filter-mapping>

回答1:


After a lot of fiddling, i learned that with the classpath notation we cannot use system variables. So i went with the following approach. This basically allows us to provide a different file name based on our environment. This variable has to be specified in catalina.properties.

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>/WEB-INF/config/${sys:log4j.fileName}</param-value>




回答2:


If your config file is named log4j2.xml and is located in the WEB-INF/ directory then you don't need to specify the log4jConfiguration context parameter in your web.xml.



来源:https://stackoverflow.com/questions/29257620/log4j2-configuration-file-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!