第一种 log4j.xml 也是与spring集成常用的方式
把原来的xml文件备份好,把这个整个贴进去,就ok了
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/ ">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<appender name="Access" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/access.log" />
<param name="Append" value="false" />
<param name="MaxFileSize" value="1024" />
<param name="MaxBackupIndex" value="2" />
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="WARN" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<appender name="Error" class="org.apache.log4j.RollingFileAppender">
<param name="Append" value="false" />
<param name="File" value="C:/error.log" />
<param name="MaxFileSize" value="1024" />
<param name="MaxBackupIndex" value="2" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="ERROR" />
<param name="LevelMax" value="ERROR" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<root>
<appender-ref ref="STDOUT" />
<appender-ref ref="Access" />
<appender-ref ref="Error" />
</root>
<appender name="IBatis" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="DEBUG" />
</filter>
</appender>
<logger name="com.ibatis" additivity="true">
<level value="DEBUG" />
</logger>
<logger name="java.sql.Connection" additivity="true">
<level value="DEBUG" />
</logger>
<logger name="java.sql.Statement" additivity="true">
<level value="DEBUG" />
</logger>
<logger name="java.sql.PreparedStatement" additivity="true">
<level value="DEBUG" />
<appender-ref ref="IBatis" />
</logger>
</log4j:configuration>
-------------------------------------------------------------
第二种是log4j.properties
#--------------------------------
#
log4j.rootLogger=DEBUG, stdout, fileout
#log4j.logger.test=info
#log4j.logger.org.apache.jasper = DEBUG
#log4j.logger.org.apache.catalina.startup.TldConfig = DEBUG
#log4j.logger.org.apache.catalina.session.ManagerBase = DEBUG
log4j.logger.com.fiscal = DEBUG
log4j.logger.com.system = DEBUG
log4j.logger.com.ibatis = DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner = DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = DEBUG
log4j.logger.java.sql.Connection = DEBUG
#log4j.logger.java.sql.Statement = DEBUG
#log4j.logger.java.sql.PreparedStatement = DEBUG
log4j.logger.java.sql.ResultSet = DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.fileout=org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File=C:\\ibatis.log
log4j.appender.fileout.MaxFileSize=10000KB
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} :%m%n
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern=[%-5p]_%d{yyyy-MM-dd HH:mm:ss} :%m%n
#log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
# log4j.logger.org=info
#--------------------------------
两种方式都来源于网络
xml:
http://wuguowei1314.iteye.com/blog/1435164
log4j.properties:
http://www.iteye.com/topic/309147
————————————————
=========================================================================
最近有的项目中,由于没有配置日志输出级别,导致debug日志满屏刷,查看日志十分痛苦,只需要简单配置一下就可以清爽的查看日志啦,配置如下:
<logger name="org.mongodb.driver.cluster">
<level value="ERROR"></level>
<!--<appender-ref ref="RollingFileError" />-->
<appender-ref ref="http_file" />
</logger>
<!--设置mongodb的连接日志级别-->
<logger name="org.mongodb.driver.connection" >
<level value="ERROR"></level>
<!--<appender-ref ref="RollingFileError" />-->
<appender-ref ref="http_file" />
</logger>
<logger name="com.alibaba.dubbo" >
<level value="ERROR" />
<appender-ref ref="http_file" />
</logger>
<logger name="org.apache.zookeeper.ClientCnxn" >
<level value="ERROR" />
<appender-ref ref="http_file" />
</logger>
配上之后,烦人的debug日志彻底消失啦!