Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

455
Views
Logging SQL statements in Spring Boot + jdbi

I'm using datasource with DBI:

@Autowired
DataSource dataSource;

@Bean
public DBI dbiBean() {
    DBI dbi = new DBI(dataSource);
    return dbi;
}

I have no idea how to configure logging framework to log SQL statements. I tried:

logging:
 level: 
   org.hibernate: TRACE
   org.skife.jdbi: TRACE
   java.sql: TRACE

but it doesn't work.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Add the line to set the SQL log like this. Use either SLF4JLog or another logger there.

@Bean
public DBI dbiBean() {
    DBI dbi = new DBI(dataSource);
    dbi.setSQLLog(new SLF4JLog());
    return dbi;
}
about 4 years ago · Santiago Trujillo Report

0

Starting from JDBI version 3.2.0, SqlLogger interface should be used:

  Jdbi jdbi;
  jdbi.setSqlLogger(new Slf4JSqlLogger());

As documentation says, Slf4JSqlLogger is a simple SqlLogger that emits some diagnostic information about Jdbi usage. You can provide existing instance of Slf4J Logger class to the Slf4JSqlLogger constructor then the provided logger will be used to log SQL statements, otherwise, if no-args constructor is used, a logger called org.jdbi.sql will be created and used.

SQL statements are logged with debug log level, so in order to see them it might be necessary to set the root level of the logging framework to debug.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!