问题描述
- log4j,控制台不打印东西,mybatis-sql也不打印
-
log4j.rootLogger=INFO,stdout,R,D log4j.appender.encoding = UTF-8 #输出到控制台 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 = INFO log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c %x - %m%n #log4j.appender.stdout.layout.encoding=UTF-8 log4j.logger.org.springframework = INFO log4j.logger.org.apache = INFO log4j.logger.com.ibatis=debug log4j.logger.com.gm.sys.mybatis.mapper = 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,stdout #输出到日志文件 log4j.appender.R = org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=target/spring.log log4j.appender.R.File = D:/gm_log/log.log log4j.appender.R.Append = true log4j.appender.R.Threshold = DEBUG log4j.appender.R.layout = org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n%c #保存异常信息到单独文件 log4j.appender.D = org.apache.log4j.DailyRollingFileAppender log4j.appender.D.File = D:/gm_log/error.log log4j.appender.D.Append = true log4j.appender.D.Threshold = ERROR log4j.appender.D.layout = org.apache.log4j.PatternLayout log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
解决方案
mybatis+log4j 打印sql
mybatis使用log4j打印sql
log4j设置控制台能打印sql语句
解决方案二:
可能你导入了多个日志工具jar,导致mybatis不知道使用哪种日志。修改你的mybatis配置,添加setting,指定日志类型为log4j。
<configuration>
<!-- 设置使用的日志类型 -->
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
</configuration>
时间: 2024-11-01 12:07:01