在项目中使用了 spring boot,orm 层集成了 mybatis-plus,按照默认配置后发现之前配置的 sql 日志正常,在这里却不正常,鉴于日志使用的是 logback,想到了打印 sql 的日志级别是 debug,所以,按照这个办法看一下问题
logback-spring.xml
INFO
${CONSOLE_LOG_PATTERN}
UTF-8
2023-10-23 16:01:15.472 INFO 22364 [XNIO-1 task-1] com.alibaba.druid.pool.DruidDataSource Caller+0 at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:972)
- {dataSource-1} inited
2023-10-23 16:01:15.601 INFO 22364 [XNIO-1 task-1] com.xxx.common.log.aspect.AbstractWebLogAspect Caller+0 at com.xxx.common.log.aspect.AbstractWebLogAspect.doAfterReturning(AbstractWebLogAspect.java:71)
- json response :
{"status":"200","message":"请求成功","result":true}
发现配置的日志 ThresholdFilter 的 level 为 info,想到是这里只做了 info 层级的日志打印,调整为 debug 试一下
DEBUG
${CONSOLE_LOG_PATTERN}
UTF-8
2023-10-23 16:14:04.609 INFO 18860 [XNIO-1 task-1] com.alibaba.druid.pool.DruidDataSource Caller+0 at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:972)
- {dataSource-1} inited
2023-10-23 16:14:04.629 DEBUG 18860 [XNIO-1 task-1] c.j.m.s.center.mapper.NotificationDao.insert Caller+0 at org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159)
- ==> Preparing: INSERT INTO notification (type, title, create_time, content, send_object, publish_type, file_path_one, file_path_two, file_path_three, new_flag) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2023-10-23 16:14:04.653 DEBUG 18860 [XNIO-1 task-1] c.j.m.s.center.mapper.NotificationDao.insert Caller+0 at org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159)
- ==> Parameters: 7(Integer), fwaefaweff(String), 2023-10-23 16:14:02.0(Timestamp), csdcd
(String), 3(Integer), 0(Integer), (String), (String), (String), 1(String)
2023-10-23 16:14:04.735 DEBUG 18860 [XNIO-1 task-1] c.j.m.s.center.mapper.NotificationDao.insert Caller+0 at org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:159)
- <== Updates: 1
2023-10-23 16:14:04.743 INFO 18860 [XNIO-1 task-1] com.cmft.common.log.aspect.AbstractWebLogAspect Caller+0 at com.cmft.common.log.aspect.AbstractWebLogAspect.doAfterReturning(AbstractWebLogAspect.java:71)
- json response :
{"status":"200","message":"请求成功","result":true}
日志打印正常。
如果把 filter 标签注释掉也可以,具体为什么可以,目前不太清楚,以后有时间啊研究一下。