JOOQ with Logback

浪尽此生 提交于 2020-03-01 04:45:46

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/36035315/jooq-with-logback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!