In my application iam using Log4j for logging.Presently I am placing log4j.xml in WEB-INF/classes. Below are the configurations i am using to load log4j.xml file.
<!-- language: xml -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Now I need to place log4j.xml file outside of my war file. The location will be most likely JBOSS_HOME/server/default/deploy/settings. In settings directory i need to place my log4j.xml.
I tried to load it by setting jboss class path by editing run.bat as follows set JBOSS_CLASSPATH=%RUN_CLASSPATH%;%JBOSS_HOME%\server\default\deploy\settings and i used below in web.xml
<!-- language: xml -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
But it throwing exception while deploying application. Exception is
java.lang.IllegalArgumentException: Invalid 'log4jConfigLocation' parameter: class path resource [/log4j.xml] cannot be resolved to URL because it does not exist
Now my question is how can I load it.
This file is main file for log4j configuration. It has information about log levels, log appenders.
the root logger that logs messages with level INFO or above in the all packages to the various destinations: console, e-mail and file, "com. foo" logger that logs messages with level WARN or above in package "com.
Remember to add "file://" in front of the path, or else it will search inside the webapp folder.
The following example works for me.
<web-app>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file://${MY_ENV_VAR}log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With