关于日志的等级 的配置

农码经神 2014-07-02

#这里定义能显示到的最低级别,若定义到INFO级别,则看不到DEBUG级别的信息了~!

log4j.rootLogger=INFO,allLog

#DAO层log记录到dao.log控制台和总日志文件

log4j.logger.DAO=INFO,dao,Console,allLog

#业务层log记录到service.log控制台和总日志文件

log4j.logger.SERVICE=INFO,service,Console,allLog

#测试及日常日志打印log记录到common.log控制台和总日志文件

log4j.logger.COMMON=INFO,common,Console,allLog

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.layout=org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=%d%p-%C{1}.%M(%L)-%m%n

log4j.appender.service=org.apache.log4j.DailyRollingFileAppender

log4j.appender.service.file=${project.root}/WEB-INF/log/service.txt

log4j.appender.service.DatePattern='.'yyyy-MM-dd

log4j.appender.service.layout=org.apache.log4j.PatternLayout

log4j.appender.service.layout.ConversionPattern=%d%p-%C{1}.%M(%L)-%m%n

log4j.appender.allLog=org.apache.log4j.DailyRollingFileAppender

log4j.appender.allLog.file=${project.root}/WEB-INF/log/allLog.txt

log4j.appender.allLog.DatePattern='.'yyyy-MM-dd

log4j.appender.allLog.layout=org.apache.log4j.PatternLayout

log4j.appender.allLog.layout.ConversionPattern=%d%p-%C{1}.%M(%L)-%m%n

log4j.appender.dao=org.apache.log4j.DailyRollingFileAppender

log4j.appender.dao.file=${project.root}/WEB-INF/log/dao.txt

log4j.appender.dao.DatePattern='.'yyyy-MM-dd

log4j.appender.dao.layout=org.apache.log4j.PatternLayout

log4j.appender.dao.layout.ConversionPattern=%d%p-%C{1}.%M(%L)-%m%n

log4j.appender.common=org.apache.log4j.DailyRollingFileAppender

log4j.appender.common.file=${project.root}/WEB-INF/log/common.txt

log4j.appender.common.DatePattern='.'yyyy-MM-dd

log4j.appender.common.layout=org.apache.log4j.PatternLayout

log4j.appender.common.layout.ConversionPattern=%d%p-%C{1}.%M(%L)-%m%n

Log4J配置后,log4j:ERRORsetFile(null,true)callfailed.报错:java.io.FileNotFoundException:\log\mytest2.log(系统找不到指定的路径。)收藏

是log4j.properties与tomcat的log4j重名的原因

你把/WEB-INF/classes/log4j.properties的log4j配置文件改个名字就OK了!(如:log.properties)

因为在tomcat启动是默认去找log4j.properties,但此时Listener还没有起来,tomcat就要往\WEB-INF\logs\log4j.log写日志就找不到了

相关springlog4j的资料

web.xml配置如下

<context-param>

<param-name>webAppRootKey</param-name>

<param-value>project.root</param-value>

</context-param>

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>classpath:log.properties</param-value>

</context-param>

<context-param>

<param-name>log4jRefreshInterval</param-name>

<param-value>6000</param-value>

</context-param>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>

<listener>

<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

</listener>

相关推荐