Skip to content

Commit

Permalink
add p6spy sql logger
Browse files Browse the repository at this point in the history
  • Loading branch information
qweezique committed Sep 11, 2022
1 parent c2d6b7b commit 0371cad
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.gavlyukovskiy</groupId>-->
<!-- <artifactId>p6spy-spring-boot-starter</artifactId>-->
<!-- <version>1.8.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.qwee.character.config;

import com.p6spy.engine.spy.appender.MessageFormattingStrategy;


public class P6spySqlPrettyFormatterLogger implements MessageFormattingStrategy {

@Override
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
// return "#" + now + " | took " + elapsed + "ms | " + category + " | connection " + connectionId + "| url " + url + "\n" + prepared + "\n" + sql + ";";
return "#" + now + " | took " + elapsed + "ms | " + category + " | connection " + connectionId + "| url " + url + "\n" + sql + ";";
}
}
11 changes: 8 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ spring:

jpa:
database: POSTGRESQL
show-sql: true
hibernate:
ddl-auto: update
open-in-view: false
properties:
generate-ddl: true
hibernate:
show_sql: false
format_sql: false
show-sql: false
datasource:
url: jdbc:postgresql://localhost:5432/ch
# url: jdbc:postgresql://localhost:5432/ch
url: jdbc:p6spy:postgresql://localhost:5432/ch
username: root
password: root
driverClassName: org.postgresql.Driver
# driverClassName: org.postgresql.Driver
driver-class-name: com.p6spy.engine.spy.P6SpyDriver

server:
port: 8080
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/spy.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#driverlist=com.mysql.cj.jdbc.Driver
#driverlist=oracle.jdbc.OracleDriver


driverlist=org.postgresql.Driver
dateformat=yyyy-MM-dd hh:mm:ss a
appender=com.p6spy.engine.spy.appender.StdoutLogger
#appender=com.p6spy.engine.spy.appender.FileLogger
#logfile=spy.log

#logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat
#logMessageFormat=com.p6spy.engine.spy.appender.MultiLineFormat
logMessageFormat=com.qwee.character.config.P6spySqlPrettyFormatterLogger

0 comments on commit 0371cad

Please sign in to comment.