4

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.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
Eugen Besel
  • 45
  • 1
  • 7
  • `log4j.xml` is the configuration file for ... wait for it ... log4j. Did you add log4j (or the slf4j-log4j bridge) as well as your Maven dependency? – Lukas Eder Mar 16 '16 at 14:23
  • here are my mvn dependency: ` log4j log4j 1.2.16 org.slf4j slf4j-api org.slf4j slf4j-log4j12 1.7.5 ` – Eugen Besel Mar 18 '16 at 18:00

1 Answers1

8

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

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509