log4jdbc 可以与 spring 引导一起使用吗?

Can log4jdbc be used with spring boot?

我有一个 Spring 启动应用程序,我正在尝试向其添加数据库日志记录,它比

spring.jpa.properties.hibernate.show_sql=true

log4jdbc,来自

https://github.com/marcosemiao/log4jdbc

似乎是最新的分支,似乎格式很好,填写参数并添加时间,正是我想要的。

但是当我按照自述文件中的说明配置它时,更改

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

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

有些东西似乎不喜欢我对 mysql 的引用,并且似乎试图回到 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)

是否有一些简单的方法可以使它协同工作?

用于 spring 引导包装程序的 log4jdbc:

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

这似乎是从以下方面引入实施:

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

附加信息:

不要修改 Spring 引导 application.properties 文件中的 spring.datasource.url 属性;保留之前定义的 URL 以访问您的 MYSQL 实例。

取而代之的是,在获取 com.integralblue maven 目标后,只需设置选择的日志记录级别(例如 logging.level.jdbc.sqltiming=info),您之前定义的 log4j 日志就会包含数据库内容。

here 原样

您需要在 build.gradle:

中使用此库
// https://mvnrepository.com/artifact/com.integralblue/log4jdbc-spring-boot-starter
compile group: 'com.integralblue', name: 'log4jdbc-spring-boot-starter', version: '2.0.0'

如果您收到警告:
"Loading class 'com.mysql.jdbc.Driver'. This is deprecated. The new driver class is 'com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary."
您可以通过属性自己设置正确的驱动程序:

log4jdbc.drivers=com.mysql.cj.jdbc.Driver  
log4jdbc.auto.load.popular.drivers=false

可以在 Github

上找到配置文档