tags:

views:

47

answers:

1

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.

    <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

      <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.

A: 

You can simply declare location of log4j configuration like this:

<context-param>
      <param-name>log4jConfigLocation</param-name>
     <param-value>${JBOSS_HOME}/server/default/deploy/settings/log4j.xml</param-value>
</context-param>
Eugene Kuleshov
I don't want hard core location of lo4j.xml bcz whenver you want to change the location of it you have to modify it in web.xml and build war file
Narendra
That's was just an example. You can use something like ${DEPLOY_SETTINGS}/log4j.xml
Eugene Kuleshov
From where can i get this value. Do i have to set it as system property?
Narendra
Either system property or environment variable.
Eugene Kuleshov