Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable debug logging in PostgreSQL JDBC/HikariCP?

I have Spring Boot 1.4.0, HikariCP 2.4.7, slf4j-api 1.7.21 and PostgreSQL JDBC 9.4.1208.

I want to see debug logs from PostgreSQL JDBC because I have some problems with HikariCP:

HikariPool-1 - Connection is not available, request timed out after 42734ms.

How can I enable debug logging to see what's going on?

I've tried:

-Adding:

org.postgresql.Driver.setLogLevel(Driver.DEBUG);
hikariDataSource = new HikariDataSource();
hikariDataSource.setLogWriter(new PrintWriter(System.out));

-Adding to VM options:

-Dorg.slf4j.simpleLogger.defaultLogLevel=debug

However, logs are the same as they were.

like image 689
Defozo Avatar asked May 24 '26 22:05

Defozo


1 Answers

Few things to consider:

Consider logging to files

1) logging to sysout may cause you to miss updates 2) it's also slow and slows your app down

Consider keeping log config in slf4j config file instead.

Consider specific Hikari config:

-Dorg.slf4j.simpleLogger.log.com.zaxxer.hikari=error

Also, by default the log level for slf4j simple logger is info. So, if you're NOT seeing anything, I don't think it's config. It may be lack of some dependency (are you just using slf4j, or something else, like log4j as well?).

Finally, are you certain that your changes are picked up at all?

Since it's hard to say on this side, let me offer another side where logging can take place: Postgres.

Try changing PG logging config:

logging_collector = on # may be 'true' for older versions as well?
log_statement = all # 'true' for older versions
log_min_error_statement = error

First turns log collector on and makes logging not lose messages. Second says everything interests you, even simple queries with syntax errors. Third gives your error level.

Docs for Postgres will tell you more.

like image 183
LAFK says Reinstate Monica Avatar answered May 26 '26 12:05

LAFK says Reinstate Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!