Search code examples
mysqlspring-bootlog4jdbc

Can log4jdbc be used with spring boot?


I have a Spring boot app I'm trying to add database logging to which is better than

spring.jpa.properties.hibernate.show_sql=true

log4jdbc, from

https://github.com/marcosemiao/log4jdbc

seems to be the most up to date fork around, seems to format nicely, fills in parameters and adds timing, exactly what I want.

But when I configure it as stated in the readme, changing

spring.datasource.url=jdbc:mysql://localhost:3306/coindatabase?useSSL=false

to

spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/coindatabase?useSSL=false

something seems to not like my reference to mysql and seems to try to fall back to H2:

Caused by: java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc:log4jdbc:mysql://localhost:3306/coindatabase?useSSL=false
  at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)

Is there some easy way to make this work together?


Solution

  • log4jdbc for spring boot wrapper:

    <groupId>com.integralblue</groupId>
    <artifactId>log4jdbc-spring-boot-starter</artifactId>
    

    which seems to pull in the implementation from:

    <groupId>org.bgee.log4jdbc-log4j2</groupId>
    <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>