My application uses Logback and I've enabled DEBUG
logging for org.jooq
in my Logback configuration. Despite this, jOOQ doesn't log the SQL queries (as it ought to). What can be causing this?

- 3,837
- 1
- 36
- 46
-
Can you share the jOOQ part of your logback configuration? You may also have a look at those 2: https://blog.jooq.org/debug-logging-sql-with-jooq/, https://stackoverflow.com/questions/8561317/how-can-we-profile-jooq-statements-for-speed – Yahor Barkouski Jun 27 '23 at 11:35
2 Answers
I'm assuming you mean logging with the org.jooq.tools.LoggerListener
, which by default DEBUG
logs all your queries and their results.
There's a flag to turn that off completely. It's enabled by default. You may have turned it off with Settings.executeLogging
.
Another reason may be that jOOQ's org.jooq.tools.JooqLogger
tries to classload org.slf4j.Logger
and logs through that if available, falling back to java.util.logging
otherwise. Do check that you make slf4j available to jOOQ on the classpath or modulepath, and that you have it backed by logback.

- 211,314
- 129
- 689
- 1,509
-
Thanks Lukas. I found out why I didn't find the logging for the query in question in my case, posted all the details here now: https://stackoverflow.com/a/76570263/227779. (I was wrong in my previous message - it _was_ logged in fact, but I might have missed it when looking at the logs) – Per Lundberg Jun 28 '23 at 05:28
-
@PerLundberg: Great to hear you've found the issue. Thanks for documenting your solution here. – Lukas Eder Jun 28 '23 at 08:30
-
Sure, np. Do you mind if I mark my own answer as the "accepted" one, or do you prefer to get the credit for this? Your answer is obviously also good, but technically this wasn't a problem with the `Settings.executeLogging` but rather that I couldn't see the forest for all the trees... ;) – Per Lundberg Jun 28 '23 at 08:37
-
1@PerLundberg: I don't care so much about "internet points" as I care about helping folks :) – Lukas Eder Jun 28 '23 at 09:28
-
Thanks, that's a good attitude. I gave you some "internet points" now anyway. :D – Per Lundberg Jun 29 '23 at 19:19
I looked at this a bit more (it was a problem I ran into last week), and it turned out I was wrong. jOOQ did indeed log the queries, using the o.j.t.L.o.j.t.LoggerListener
. The problem was just this:
I was running different queries on multiple threads.
Other queries were being logged after this query.
This particular query returned 21 million records, leading to the following:
java.lang.OutOfMemoryError: Java heap space Dumping heap to /tmp/java_pid104782.hprof ... Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-0 (ActiveMQ-scheduled-threads)" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "I/O dispatcher 14" Heap dump file created [6088668813 bytes in 48.331 secs] Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "req-rsp-timeout-task" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "I/O dispatcher 5" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "lettuce-eventExecutorLoop-1-3" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "I/O dispatcher 11"
Because of the above, the
Fetched result
andFetched row(s)
messages were never logged. And in general, it was hard to understand that it was that specific query that failed, because it wasn't the "last" query to be logged, so to speak (because of the queries from the other threads).
What I did to mitigate this was to add an onRenderEnd
handler for the particular query that was failing (I stepped through the code with the debugger to roughly see which jOOQ query this was). Using this, I was able to pin-point the logging for my particular query more easily.
Posting all these details in the help that it might help others and/or my future self.
diff --git a/path/to/MyClass.java b/path/to/MyClass.java
index 92beaa9a91..fcddf9c134 100644
--- a/path/to/MyClass.java
+++ b/path/to/MyClass.java
@@ -30,6 +30,7 @@ import java.util.stream.Stream;
import org.jooq.DSLContext;
import org.jooq.DatePart;
+import org.jooq.ExecuteListener;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.Record1;
@@ -417,6 +418,10 @@ public class MyClass {
// arithmetics on `Field<Instant>` https://stackoverflow.com/a/71508599
Field<Instant> upperRelatedLimit = field( "(" + seriesTimeFieldName.first() + " + INTERVAL '1 hour')", Instant.class );
+ create.configuration().set( ExecuteListener.onRenderEnd( ctx -> {
+ System.out.println( ctx.sql() );
+ } ) );
+
try ( Stream<AssignedDeviceConnectionState> connectionStates = auditDsl.select(
field( "series." + seriesTimeFieldName.first(), Instant.class ).as( "time" ),
field( "d.id", Integer.class ).as( "device_id" ),

- 3,837
- 1
- 36
- 46