Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOOQ with Logback

I use springBoot with JOOQ and would like to log generated SQL's.

I added slf4J to my maven dependency and log4j.xml like in JOOQ documenation (http://www.jooq.org/doc/latest/manual/sql-execution/logging/). But when jooq executes some queries, I can not see any log in my console.

I also search for this issue in google, but I couldn't find anything. SpringBoot uses logBack, so I have logBack and slf4J in my path. Is it possible to use logBack for JOOQ ? I didnt any instruction on JOOQ Site about it.

like image 656
Eugen Besel Avatar asked Feb 07 '23 11:02

Eugen Besel


1 Answers

jOOQ's built-it JooqLogger tries to resolve an optional logger dependency in the following order:

  • If slf4j is found on the classpath, that is used
  • Else, if log4j is found on the classpath, that is used
  • Else, java.util.logging is used

So, as soon as the JooqLogger finds slf4j on the classpath (e.g. as a transitive dependency from spring boot), it will use that as a logging framework. This is reasonable, because slf4j can be configured to delegate to any other logging framework, including log4j and java.util.logging.

So, in order to enable jOOQ's debug logging via logback and Spring Boot, it is sufficient to put the following logback.xml file at your classpath root:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="org.jooq" level="DEBUG"/>
</configuration>

This is now also reflected in the jOOQ-spring-boot-example on GitHub.

Some more ideas can be found here in the Spring Boot manual: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html

like image 146
Lukas Eder Avatar answered Feb 13 '23 23:02

Lukas Eder