Logback: logger additivity=false 플래그

Jongho Jeon
Jongho’s Tech Blog
3 min readOct 23, 2022

Overview

logback config(xml) 파일에서 아래와 같이 additivity=“false”라는 플래그를 설정할 수 있다.

  <logger name="chapters.configuration.​Foo" additivity="false">
<appender-ref ref="FILE" />
</logger>

이 때 log가 어떻게 출력되는지에 대해 간단히 설명한다.

Logback은 Spring Boot에서 가장 많이 사용되는 logging 구현체 중 하나이다.

additivity=“true” (default)

additivity를 직역하면 가산성이라고 할 수 있다. 무언가 추가할 수 있다는 의미다.

additivity의 기본값은 true이며, logger는 상위 logger(root logger 포함)들의 설정들이 누적되어 적용된다.

additivity=“false”

logger에 additivity=”false”플래그를 설정해주면, 상위 logger들의 설정들을 적용받지 않는다.

In case the default cumulative behavior turns out to be unsuitable for your needs, you can override it by setting the additivity flag to false. Thus, a branch in your logger tree may direct output to a set of appenders different from those of the rest of the tree.

위 문장은 아래 공식 문서의 Overriding the default cumulative behaviour 부분을 인용했다.

사용 사례 (Use case)

root logger에 기본적으로 2개의 appender를 적용해서 사용하고 있다.

  • STDOUT으로 출력
  • WARN level 이상은 Slack 채널로 전송 (Slack appender라고 하자)

그런데 특정 logger의 경우 Slack 채널로 전송되지 않도록 변경해야 했다. 코드를 변경할 수 없는 외부 라이브러리의 logger였기 때문이다.

해당 logger의 설정에 additivity=”false”플래그를 적용하면 root logger의 appender가 적용되지 않는다. 따라서 특정 logger에만 Slack appender가 적용되지 않도록 할 수 있었다.

Reference

--

--