How to track SQL queries for H2 in memory databases?

How can I track SQL queries for embedded databases inside the built-in memory?

The documentation states that the trace file is in the same directory as the database file, but for the built-in database in memory I do not have a database directory (for Windows).

I tried redirecting traces to a given file using slf4j / logback using

TRACE_LEVEL_FIle=4;TRACE_LEVEL_SYSTEM_OUT=3 

into the database url and the following logback.xml configuration file, but no luck:

 <configuration scan="true"> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>mylogfile.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>%d{yyyyMMdd}_mylogfile.log</fileNamePattern> </rollingPolicy> <encoder> <pattern>%date{yyyyMMdd HH:mm:ss} %contextName[%thread] %level %logger{0} - %msg%n</pattern> </encoder> </appender> <logger name="com.myapp" level="WARN"> <appender-ref ref="FILE" /> </logger> <logger name="h2database" level="TRACE"> <appender-ref ref="FILE" /> </logger> --> <root level="WARN"> <appender-ref ref="FILE" /> </root> </configuration> 

My log configuration file works correctly for other logs.

Any idea?

+7
source share
1 answer

I'm not quite sure, but according to my test, it seems that you remove TRACE_LEVEL_SYSTEM_OUT=3 , then it will work. Could you try this? Example database url:

 jdbc:h2:mem:test;TRACE_LEVEL_FIle=4 

instead

 jdbc:h2:mem:test;TRACE_LEVEL_FIle=4;TRACE_LEVEL_SYSTEM_OUT=3 
+2
source

All Articles