Java EmbeddedDatabase (H2) logging

575 Views Asked by At

I would like to change the logging of my EmbeddedDatabase. Atm every time I open a connection it logs "... Creating new JDBC Driver Connection to ...". In my test suite, I open for every request a new connection, and now there are way too many of these messages.

EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
            .generateUniqueName(true)
            .setType(EmbeddedDatabaseType.H2)
            .build();
...
Connection connection = embeddedDatabase.getConnection();

I didn't find any kind of log level. I just can set the PrintWriter. But I wanna see the error msgs. I run this outside of spring as a regular unit test.

Any ideas?

1

There are 1 best solutions below

0
Retardo On

It seem like the getConnection method from the EmbeddedDatabase and from the DriverManager create a different log strategie for the connection. The default config fits for my problem. So the code would look like this:

new EmbeddedDatabaseBuilder()
            .setName("test")
            .setType(EmbeddedDatabaseType.H2)
            .build();
...
Connection connection = DriverManager
       .getConnection("jdbc:h2:mem:test", "sa", "");
... or
Connection connection = DriverManager
       .getConnection("jdbc:h2:mem:test;TRACE_LEVEL_SYSTEM_OUT=3", "sa", "");

More options: https://h2database.com/html/features.html#trace_options