LoginSignup
4
3

More than 5 years have passed since last update.

slf4j x logback で実行時に appender を取り除く

Posted at

slf4j 経由で logback 使ってる前提の話です。

例えばこんな感じで定義してある時に

<root level="ERROR">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="EMAIL" />
</root>

テストの時だけは EMAIL へのログ出力をしたくない!といったときは、こう書いておけば appender を除去できます。

import ch.qos.logback.classic.LoggerContext;
import org.slf4j.LoggerFactory;

((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("ROOT").detachAppender("EMAIL");
4
3
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
4
3