Announcement Announcement Module
Collapse
No announcement yet.
environment specific log4j configuration by spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • environment specific log4j configuration by spring

    I am loading log4j.xml using the traditional way

    Code:
    <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>classpath:conf/log4j.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>
    This works fine but now I need to load a different log4j.xml file based on which environment I am in which is defined by a environment variable/jndi entry .. so I was hoping that with new spring 3.1 property management I could just change this to

    Code:
    <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>classpath:conf/log4j-${WASENV}.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>
    and spring will load the correct log4j file in each environment but this doesnt works probably because web.xml is loaded before spring. I came across this method

    Code:
    <!-- log4j setting -->
        <bean id="log4jInitialization"
     class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
      <property name="targetClass"
       value="org.springframework.util.Log4jConfigurer" />
      <property name="targetMethod" value="initLogging" />
      <property name="arguments">
       <list>
        <value>log4j-${WASENV}.xml</value>
       </list>
      </property>
     </bean>
    so essentially moving configuration of log4j into spring context file instead of web.xml. Is there a cleaner way to do this.

    Any help would be appreciated.
    Thanks
    Adeel

  • #2
    may be I can ask the question in a different way. What is the preferred method of log4j configuration using spring with environment specific log4j properties in mind.

    Comment

    Working...
    X