How do I turn on SQL query logging for a Dropwizard application? I would like it to only log SQL in certain environments.
How do I log SQL Statements in Dropwizard
In your application YAML file add a "logging:" definition like the following:
# Logging settings.
logging:
# The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
level: INFO
# Logger-specific levels.
loggers:
# Overrides the levels of certain packages or files.
"org.skife.jdbi.v2": TRACE
This does not help. The SQL statement is logged but with parameters shown as simple '?' like: "SELECT * FROM XY WHERE ID = ?" –
Playlet
If that is what you need @heaphach, hopefully you can use a debugger to figure out what parameters are being passed in. For the question I had above, this answer is sufficient and accurate, even if it does not solve your particular issue. –
Honorific
Yeah for me its clear what SQL is ued, but some managers want to log the exact SQL statement. However you are right, you answered the question above. –
Playlet
Are you using jdbi?, if so, this is working for me:
Set a logger when you create the DBI instance:
DBI dbi = new DBI(dataSource);
dbi.setSQLLog(new SLF4JLog());
Add this configuration to your config file:
logging:
level: INFO
loggers:
"org.skife": TRACE
I guess this idea should be also valid for Hibernate or any other DB access framework.
Using jdbi 3, I had to configure the Slf4JSqlLogger
like this:
jdbi.setSqlLogger(new Slf4JSqlLogger());
... And set the log level of org.jdbi.sql
to TRACE
in my config.yaml
:
logging:
level: INFO
loggers:
org.jdbi.sql: TRACE
© 2022 - 2024 — McMap. All rights reserved.