How to trace SQL requests for H2 in-memory databases


How can I trace SQL requests for H2 in-memory embedded databases?

The documentation says the trace file is located in the same directory as the database file, but for in-memory embedded database I have no database directory (under Windows).

I tried to redirect traces to a given file with slf4j/logback by using


in the database URL and the following logback.xml config file but with no luck:

<configuration scan="true">
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <pattern>%date{yyyyMMdd HH:mm:ss} %contextName[%thread] %level %logger{0} - %msg%n</pattern>

  <logger name="com.myapp" level="WARN">
    <appender-ref ref="FILE" />

  <logger name="h2database" level="TRACE">
    <appender-ref ref="FILE" />
  </logger> -->

  <root level="WARN">
    <appender-ref ref="FILE" />

My logback config file works correctly for other logs.

Any idea?

Best Solution

I'm not completely sure, but according to my test it seems if you remove TRACE_LEVEL_SYSTEM_OUT=3 then it would work. Could you try this? Example database URL:


instead of


Related Question