Print sql through druid using info level in springBoot
- 2021-11-13 07:42:44
- OfStack
Directory springBoot info level prints sqlapplication through druid. log related configuration in yml adds the following configuration to print sql using druid
springBoot info level prints sql through druid
My springBoot uses logback to output logs.
The relevant configuration of log in application. yml is as follows
logging:
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5p) %clr([%15.15t]){cyan} %clr(%X{__traceId}){magenta} %clr(%-40.40logger{39}){blue} %clr(:) %m%n"
file: "%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] %X{__traceId} %-40.40logger{39} : %m%n"
level:
com.xxx.xxx.xxx.repository.mybatis.mapper: debug # Settings mapper.java Package is debug Output
file: c:/tmp/xxx-xxx-web/log.log
file.max-history: 30
If the project log level is info, the sql statement will not be printed (it will be printed under debug level). If you want to print sql under info level, you need to print application. yml
The following configuration is added to the druid configuration section
druid:
filter:
commons-log:
#data-source-log-enabled: true
statement-log-enabled: true
statement-executable-sql-log-enable: true
Through the above configuration, sql can be printed through druid under the condition that the log level is info;
Advantages of printing out sql using druid
21:26:52,515 DEBUG druid.sql.Statement:137 - {conn-10005, pstmt-20007} executed. 2.301113 millis. select
ID, AREA_ID, PARENT_AREA_ID, AREA_NAME, AREA_LEVEL, DESCRIPTION, LAST_UPDATE_TIME,
LAST_UPDATE_BY, DELETE_FLAG, DELETE_BY, DELETE_TIME
from RMS_AREA
where
DELETE_FLAG='0'
ORDER BY AREA_ID DESC