[Spring Data JPA Logging] Logging SQL with p6spy-spring-boot-starter in Spring Boot
Logging SQL with p6spy
P6Spy is a framework that enables database data to be seamlessly intercepted and logged with no code changes to existing application. The P6Spy distribution includes P6Log, an application which logs all JDBC transactions for any Java application.
Spring Boot autoconfiguration is handled by the separate project: gavlyukovskiy/spring-boot-data-source-decorator: Spring Boot integration with p6spy, datasource-proxy, flexy-pool and spring-cloud-sleuth - https://github.com/gavlyukovskiy/spring-boot-data-source-decorator, please consult the respective documentation for usage.
Installation
Spring Boot integration with p6spy, datasource-proxy and flexy-pool.
Gradle
1 | // bundle.gradle |
Maven
1 | <!-- pom.xml --> |
Configuration
Spring Boot Configuration
Update database url and driver class:
1 | # application.properties |
Or application.yml
1 | # application.yml |
Replace jdbc:p6spy:postgresql
to jdbc:p6spy:mysql
or others in other databses.
p6spy Configuration
Configuration follows layered approach, where each layer overrides the values set by the lower ones (leaving those not provided unchanged):
-
JMX set properties (please note, that these are reset on next reload)
-
System properties
-
Environment variables
-
spy.properties
-
defaults
For the full list of available options, see the section Common Property File Settings. Please note that providing any of these via System properties/Environment variables is possible, using the particular property name following naming rule: p6spy.config.<property name><property value>
;
See Configuration and Usage - https://p6spy.readthedocs.io/en/latest/configandusage.html to learn more.
References
[2] p6spy — p6spy 3.9.2-SNAPSHOT documentation - https://p6spy.readthedocs.io/en/latest/index.html