This is trickier than you'd imagine. I wanted:
- Several services running on jboss
- Each service outputting to a separate log file
- Each log4j.xml configuration to be available to edit outside of the war file
1)
first of all have the following configured in your web.xml file:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file:--file location on host--</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
If you're using maven substitution you'll need to make sure that you have the following in your pom in order to have it replace variables in your web.xml:
<webResources>
<webResource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<includes>
<include>web.xml</include>
</includes>
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
Then finally, you need to make sure that you are including log4j-1.2.14.jar, but excluding the other commons logging jars and excluding other log4j xml files in the war file that you produce. This weird and wonder combination achieves the separate log files. In maven you can exclude jars by putting <scope>provided</scope> on dependencies.
No comments:
Post a Comment