springMVC 项目在jboss7中配置应用自己的log4j

来源:互联网 发布:尼古拉斯凯奇现状 知乎 编辑:程序博客网 时间:2024/05/17 00:04

原文地址:http://www.xuebuyuan.com/1954635.html

Jboss7默认采用容器自己的log4j module,应用自己配置的log4j不起作用,需要应用做一些设置:

以springMVC项目为例:

1> 在WEB-INF下新建文件jboss-deployment-structure.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?><jboss-deployment-structure>   <deployment>     <exclusions>       <module name="org.apache.log4j" />     </exclusions>   </deployment></jboss-deployment-structure> 

2> 在web.xml里配置

<context-param><param-name>log4jConfigLocation</param-name><param-value>/WEB-INF/log4j.properties</param-value></context-param>
<listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener>

 

3> 在WEB-INF下新建log4j.properties

# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.log4j.rootLogger=INFO,logfile#log4j.appender.stdout=org.apache.log4j.ConsoleAppender#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout#log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%nlog4j.appender.logfile=org.apache.log4j.RollingFileAppenderlog4j.appender.logfile.File=${jboss.server.log.dir}/YOURAPP.loglog4j.appender.logfile.MaxFileSize=512KB# Keep three backup files.log4j.appender.logfile.MaxBackupIndex=3# Pattern to output: date priority [category] - messagelog4j.appender.logfile.layout=org.apache.log4j.PatternLayoutlog4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

4> pom添加依赖

<dependency>        <groupId>log4j</groupId>        <artifactId>log4j</artifactId>        <version>1.2.17</version> </dependency>
0 0