ibatis配置log4j输出sql语句等日志信息

帖子地址[url]http://www.iteye.com/topic/309147[/url]

1.建立一个log4j.properties文件,放到工程源文件夹下,如果是eclipse那么放到src下,eclipse会自动将这个文件加载到class目录下。如下图

[img]http://www.iteye.com/upload/picture/pic/28873/3cf2871e-6698-38c8-a76a-f450b30cbd62.bmp[/img]
2.将log4j.jar和commons-logging.jar(我这次就是落下了这个jar,日了!)放到项目的类路径中,如果是web项目就是lib下。
3.配置的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方式的配置


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender class="org.apache.log4j.ConsoleAppender" name="console">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n" />
<!-- param name="ConversionPattern"
value="=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n" /-->
</layout>
</appender>
<appender class="org.apache.log4j.RollingFileAppender"
name="file">
<param name="File" value="MengBackup.log" />
<param name="MaxFileSize" value="100KB" />
<param name="MaxBackupIndex" value="2" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n" />
</layout>
</appender>

<logger name="com.ibatis">
<level value="debug" />
</logger>

<logger name="com.ibatis.common.jdbc.SimpleDataSource">
<level value="debug" />
</logger>

<logger name="com.ibatis.common.jdbc.ScriptRunner">
<level value="debug" />
</logger>

<logger name="com.ibatis.common.jdbc.SqlMapClientDelegate">
<level value="debug" />
</logger>

<logger name="java.sql.Connection">
<level value="debug" />
</logger>

<logger name="java.sql.Statement">
<level value="debug" />
</logger>

<logger name="java.sql.PreparedStatement">
<level value="debug" />
</logger>

<logger name="java.sql.ResultSet">
<level value="debug" />
</logger>

<root>
<priority value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</root>
</log4j:configuration>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值