One of jOOQ’s most popular feature is the out-of-the-box debug logging experience. jOOQ developers find this feature very useful when developing their applications. Assuming you run a jOOQ query and configure your logger to print DEBUG log output:
ctx.select(BOOK.ID, BOOK.TITLE) .from(BOOK) .orderBy(BOOK.ID) .limit(1, 2) .fetch();
When this query is executed, your log output might contain something like this:
Executing query : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc limit ? offset ?
-> with bind values : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc limit 2 offset 1
Fetched result : +----+------------+
: | ID|TITLE |
: +----+------------+
: | 2|Animal Farm |
: | 3|O Alquimista|
: +----+------------+
The query is logged as it is executed with bind variables. It is also logged with inline bind values for debugging. Additionally, the first 5 records of its result are logged, if any.
Now, this is really useful as a developer, but not really as much if you’re in production, mainly because of the sheer amount of log output this produces, but also for security reasons. You do not want to leave a trail of certain sensitive data in any log files, including by accident. The fetched result is printed as such simply by calling Result.toString() on the jOOQ Result type, so this content isn’t unique to jOOQ’s out-of-the-box debug logging, but it could happen anywhere you output data to.
Perhaps you prefer not to print out the BOOK.TITLE content. The commercial jOOQ distributions have you covered. All you have to do is specify a code generation configuration like so (assuming Maven):
<configuration> <generator> <database> <forcedTypes> <forcedType> <redacted>true</redacted> <includeExpression>(?i:BOOK\.TITLE)</includeExpression> </forcedType> </forcedTypes> </database> </generator></configuration>
And from now on, whenever a Record or Result is exported as text (including DEBUG log output) or HTML (and optionally also as CSV, JSON, or XML), it will print as follows:
Executing query : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc limit ? offset ?
-> with bind values : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc limit 2 offset 1
Fetched result : +----+-----+
: | ID|TITLE|
: +----+-----+
: | 2|**** |
: | 3|**** |
: +----+-----+
For more information about this jOOQ 3.21 feature, refer to the manual.
