- pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.22</version>
</dependency>
Copy the code
- logback-spring.xml
<configuration>
<springProfile name="dev-py">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder charset="UTF-8"> <! Encoder can specify a character set that is meaningful for Chinese output -->
<pattern><! [CDATA[ %-5level %d{HH:mm:ss} %thread %c.%M\(%L\) %msg%n ]]></pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
<logger name="com.open" level="ERROR"/>
<logger name="org.apache.tomcat.jdbc" level="WARN"/>
<! SQL > select * from 'SQL';
<logger name="java.sql" level="DEBUG"/>
<! -- This configuration will simply print the parameters -->
<Logger name="druid.sql.Statement" level="trace" additivity="false">
<appender-ref ref="STDOUT"/>
</Logger>
</springProfile>
</configuration>
Copy the code
Configuring SQL Output
-
yml
spring: servlet: multipart: max-file-size: 20MB max-request-size: 20MB location: D:/tmp enabled: true file-size-threshold: 1MB Write to disk when the uploaded file reaches 1MB datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://xxx:3306/xx? allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8 username: uu password: uu druid: initialSize: 5 minIdle: 5 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 1 testWhileIdle: true testOnBorrow: false testOnReturn: false # jmx-enabled: true # Configure the filters for monitoring statistics interception. After removing the filters, the MONITORING interface SQL cannot be counted. 'wall' is used for the firewall filters: stat,wall,slf4j Enable mergeSql via connectProperties; Slow SQL record connectionProperties: druid.stat.mergeSql\=true; druid.stat.slowSqlMillis\=5000 # configuration DruidStatFilter web-stat-filter: enabled: true url-pattern: "/ *" exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" # configuration DruidStatViewServlet stat-view-servlet: enabled: true url-pattern: "/druid/*" # IP whitelist (not configured or empty, all access allowed) allow: 127.0. 01.192.168. * # IP blacklist (deny takes precedence over allow if common) # deny: 192.168.1.100 # Disable the Reset All function on HTML pages reset-enable: false # login name login-username: admin # login password login-password: 123456 filter: slf4j: statement-executable-sql-log-enable: true enabled: true statement-parameter-set-log-enabled: false statement-execute-query-after-log-enabled: false statement-prepare-after-log-enabled: false statement-execute-after-log-enabled: false statement-prepare-call-after-log-enabled: false statement-close-after-log-enabled: false Copy the code