在mybatis中,这样设置
<settings> <setting name="logImpl" value="LOG4J"/> </settings>
配置log4j.properties
#//注意这里不要用INFO,DEBUG等 改个名字 log4j.rootLogger=infoA,errorA,stdout,DEBUGA #过滤掉spring框架下的额外日志 log4j.category.org.springframework = WARN #输出到控制台 log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.Threshold = debug log4j.appender.stdout.layout.ConversionPattern=%d %-5p %c{1}:%L - %m%n #输出error到指定文件 log4j.logger.errorA=error log4j.appender.errorA=org.apache.log4j.DailyRollingFileAppender log4j.appender.errorA.layout=org.apache.log4j.PatternLayout log4j.appender.errorA.layout.ConversionPattern=%d{yyyy-MM-dd-HH-mm} [%t] [%c] [%p] - %m%n log4j.appender.errorA.datePattern=yyyy-MM-dd'.log' log4j.appender.errorA.Threshold = error log4j.appender.errorA.append=true log4j.appender.error.File=d:/java/log4j/error.log #输出DEBUG信息到指定文件 log4j.logger.DEBUGA=DEBUG log4j.appender.DEBUGA=org.apache.log4j.DailyRollingFileAppender log4j.appender.DEBUGA.layout=org.apache.log4j.PatternLayout log4j.appender.DEBUGA.layout.ConversionPattern=%d{yyyy-MM-dd-HH-mm} [%t] [%c] [%p] - %m%n log4j.appender.DEBUGA.datePattern=yyyy-MM-dd'.log' log4j.appender.DEBUGA.Threshold = DEBUG log4j.appender.DEBUGA.append=true log4j.appender.DEBUGA.File=d:/java/log4j/debug_log.log #打印sql语句 log4j.logger.com.ibatis=DEBUG log4j.logger.java.sql.ResultSet=INFO 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
默认配置如下
# Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE debug info warn error fatal log4j.rootCategory=info, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPatern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m t # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=d:axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m