Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I log SQL Statements in Dropwizard

How do I turn on SQL query logging for a Dropwizard application? I would like it to only log SQL in certain environments.

like image 368
th3morg Avatar asked Mar 30 '15 18:03

th3morg


People also ask

Should you log DB queries?

So, yes, it is ok to run debug logs of queries, as long as you secure and control it in line with the protections the data requires.

How do I enable SQL logging in hibernate?

Hibernate has build-in a function to enable the logging of all the generated SQL statements to the console. You can enable it by add a “show_sql” property in the Hibernate configuration file “ hibernate. cfg. xml “.

Does SQL Server log queries?

SQL Statements are saved in a list written to a file and/or a database. The solution can delete the older SQL query history logs automatically. Additionally, you can monitor who and when executed any particular query, or receive other valuable information for research and analysis.


1 Answers

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.

like image 84
colo Avatar answered Sep 17 '22 20:09

colo