How do I log postgres driver messages with slf4j?

New Postgres driver 42.0.0 use java.util.logging, see changelog

To get logs:

  1. Add jul-to-slf4j bridge:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    
  2. Add in logback.xml (logback-test.xml)

    <logger name="org.postgresql" level="trace"/>`
    
  3. Add in code

    static {
        SLF4JBridgeHandler.install();
    }
    

You can set a PrintWriter as the PostgresQL driver logging destination. For example, if you were using one of the driver data sources, you would use this method.

Now, all you need is an extension of PrintWriter that sends everything it receives to your logging system. Here is an example from Apache Jackrabbit.