10
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mybatisのクエリをlogbackで出力する

Posted at

設定

クエリ内容の出力は、作成したMapperをnameとしてDEBUGレベルで出力されるよう。
なのでlogback.xmlはこんな感じ。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
		</encoder>
	</appender>

    <!-- MapperのあるパッケージをDEBUGレベルに -->
	<logger name="com.example.mappers" additivity="false">
		<level value="DEBUG" />
		<appender-ref ref="STDOUT" />
	</logger>

	<root level="info">
		<appender-ref ref="STDOUT" />
	</root>
</configuration>

出力イメージ

1クエリに付き2行。

==>  Preparing: [クエリ本体]
==> Parameters: [パラメータ1]([型]), [パラメータ2]([型]), ...

パラメータが多いと結構重いので、パッケージでひとまとめに括るより見たいMapperだけを指定したほうが良いかもしれない。

10
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?