使用springboot默认的日志系统logback打印Mybatis语句问题


在yml配置文件中,配置mybatis时,一般有如下配置

mybatis:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true
  typeAliasesPackage: XXXX
  mapper-locations: classpath*:**/xml/*Mapper.xml

log-impl指定的值为org.apache.ibatis.logging.Log接口的某个实现类,是设置打印mybatis的日志实现,

如果配置为org.apache.ibatis.logging.stdout.StdOutImpl就只会在控制台窗口打印,不会记录到日志文件。如果需要保存打印的SQL到文件就不能设置为StdOutImpl,可以设置为Slf4jImpl,也可以不设置。然后对应接口所在包设置logback对应包的日志等级

# 日志配置
logging:
  level:
    com.XXX: debug
    org.springframework: warn
    org.apache.ibatis.logging: debug

这样就可以把mybatis的打印内容,保存到文件中了。

注意:如果在logback-spring.xml文件中通过下面的方式配置的时候:

    <springProfile name="dev,test,prod">
        <root level="info">
            <appender-ref ref="console"/>
            <appender-ref ref="logFile"/>
        </root>
    </springProfile>

需要在yml配置文件中添加:

spring:
  profiles:
    active: dev

不然在控制台或者文件中是空白的


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM