mybatis打印sql遇到sl4j与log4j冲突问题解决.

改造一个旧系统的持久层HeIbernate改为mybatis

这个项目由于sl4j与log4j都必须存在

遇到调试mybatis sql无法打印问题

用度娘找了很久,最后发现大家都是相互copy的,鄙视各种copy,感谢万能的google

下面是解决方法

我使用的maven为构建工具,首先加入日志依赖包

                <!-- Logging -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>

 

 

 然后修改log4j.properties

 

 

###################
# COMMON
###################
log4j.appender.encoding = UTF-8

log4j.rootLogger=INFO,DEBUG,CONSOLE,APPLOG,ERRORLOG,stdout

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c %x - %m%n

###################
# APPLOG
###################
log4j.appender.APPLOG=org.apache.log4j.DailyRollingFileAppender
log4j.appender.APPLOG.Append=true
log4j.appender.APPLOG.DatePattern='_'yyyyMMdd'.log'
log4j.appender.APPLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.APPLOG.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c %x - %m%n
log4j.appender.APPLOG.File=/data1/logs/bxcms/AppAccessLog


###################
# ERRORLOG
###################
log4j.appender.ERRORLOG=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ERRORLOG.Threshold=ERROR
log4j.appender.ERRORLOG.Append=true
log4j.appender.ERRORLOG.DatePattern='_'yyyyMMdd'.log'
log4j.appender.ERRORLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.ERRORLOG.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c %x - %m%n
log4j.appender.ERRORLOG.File=/data1/logs/bxcms/AppErrorLog

###显示SQL语句部分
# MyBatis logging configuration...
log4j.logger.cn.com.softvan.cms.dao=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
### mybatis loggers ###
log4j.logger.com.ibatis=DEBUG,stdout
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG,stdout
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG,stdout
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG,stdout
# sql loggers
log4j.logger.java.sql.Connection=DEBUG,stdout
log4j.logger.java.sql.Statement=DEBUG,stdout
log4j.logger.java.sql.PreparedStatement=DEBUG,stdout
log4j.logger.java.sql.ResultSet=DEBUG,stdout


 

log4j.logger.cn.com.softvan.cms.dao=TRACE 这句一定要加 不然无法打印SQL,其它的自己看情况简化

cn.com.softvan.cms.dao为包路径

 

 

你可能感兴趣的:(mybatis log sql)