传销网站建设,衡水建网站费用,wordpress主题Tendor,邯郸网站建设做公司环境#xff1a;项目非完全spring项目#xff0c;没有spring的配置文件。执行sql时老是不打印sql语句。因此进行修改#xff0c;过程比较坎坷#xff0c;记录一下。 我尝试使用log4j和log4j2进行配置 最终把这两种全部配置记录上 Log4j配置 如果项目用的是log4j需要进行配置…环境项目非完全spring项目没有spring的配置文件。执行sql时老是不打印sql语句。因此进行修改过程比较坎坷记录一下。 我尝试使用log4j和log4j2进行配置 最终把这两种全部配置记录上 Log4j配置 如果项目用的是log4j需要进行配置打印sql的步骤
首先引入log4j的包配置一下log4j的配置文件
#STDOUT 表示配置sql语句输出
log4j.rootLoggerERROR,STDOUT
#xxx代表你项目中的mapper路径
log4j.logger.xxx.xxx.xxxDEBUGlog4j.appender.STDOUTorg.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.TargetSystem.out
#log4j.appender.STDOUT.layoutorg.apache.log4j.PatternLayout
log4j.appender.STDOUT.layoutorg.apache.log4j.EnhancedPatternLayout
log4j.appender.STDOUT.layout.ConversionPattern%-d{yyyy-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m%n
Log4j2配置 如果使用log4j2需要进行配置打印sql的步骤
引入log4j2包配置log4j2配置文件
Configuration statusWARNAppendersConsole namemyConsole targetSYSTEM_OUTPatternLayout pattern[%d{MM-dd HH:mm:ss} %-5p] [%t] %c{2\} - %m%n%ex//ConsoleConsole namemyConsole2 targetSTDOUTPatternLayout pattern[%d{MM-dd HH:mm:ss} %-5p] [%t] %c{2\} - %m%n%ex//ConsoleRollingFile nameactivexAppender fileName../log/jxedtgouchescf.log filePattern../log/jxedtgouchescf.log.%d{yyyy-MM-dd}.logPatternLayoutPattern[%d{MM-dd HH:mm:ss SSS} %-5level] [%t] %c{3} - %m%n%ex/Pattern/PatternLayoutPoliciesTimeBasedTriggeringPolicy//Policies/RollingFile/AppendersLoggersRoot levelinfoAppenderRef refmyConsole/AppenderRef refactivexAppender//Root!--这里的name为你自己mapper的地址--Logger namexxx.xxx.mapper levelDEBUGAppenderRef refmyConsole//Logger/Loggers
/Configuration
ok这样就能打出来具体的执行sql了
[12-13 17:20:32 DEBUG] [main] cxxxx.xxxx.xxx.selectCount - Preparing: SELECT COUNT(1) FROM table WHERE (state ?)
[12-13 17:20:32 DEBUG] [main] cxxxx.xxxx.xxx.selectCount - Preparing: SELECT COUNT(1) FROM table WHERE (state ?)
[12-13 17:20:32 DEBUG] [main] cxxxx.xxxx.xxx.selectCount - Parameters: 0(Integer)
[12-13 17:20:32 DEBUG] [main] cxxxx.xxxx.xxx.selectCount - Parameters: 0(Integer)
[12-13 17:20:32 DEBUG] [main] cxxxx.xxxx.xxx.selectCount - Total: 1
[12-13 17:20:32 DEBUG] [main] cxxxx.xxxx.xxx.selectCount - Total: 1这里顺便提一下mybatisplus开启打印日志的配置方法适用于spring-boot