버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

목차

Spring Boot의 로깅 설정

다음은 Spring Boot에서 지원하는 로깅 설정입니다. Spring Boot 버전에 따라서 다를 수 있습니다.

Trace 모드 적용

다음은 --trace 옵션을 추가함으로써 Trace 레벨로 실행할 수 있습니다.

코드 블럭
languagetext
linenumberstrue
# java -jar target/spring-boot-logging-0.0.1-SNAPSHOT.jar --trace

파라미터로 Lgoging Level 변경

다음과 같이 -D 옵션을 이용하면 특정 패키지의 로깅 레벨을 변경할 수 있습니다.

코드 블럭
languagetext
linenumberstrue
-Dlogging.level.org.springframework=TRACE 
-Dlogging.level.io.datadynamics=TRACE

application.yml 파일로 Logging 설정

이 방식은 Logback용 로깅 설정 파일을 별도로 두지 않는 방식으로 간단하게 적용할 수 있습니다.

...

코드 블럭
languageyml
linenumberstrue
###################
## Logging
###################
 
logging:
  level:
    root: INFO
    tomcat: INFO
    freemarker: INFO
    jdbc.connection: WARN
    jdbc.audit: WARN
    jdbc.sqlonly: WARN
    jdbc.resultset: WARN
    jdbc.resultsettable: DEBUG
    org.hibernate: INFO
    org.springframework: INFO
    org.springframework.session: WARN
    io.datadynamics: DEBUG
    org.apache: INFO
    com.zaxxer: INFO
  group:
    tomcat: org.apache.catalina, org.apache.coyote, org.apache.tomcat

Logback 설정 파일로 Logging 별도 설정

Spring Boot의 기본 로깅 Logback 설정 파일

Spring Boot는 다음의 파일에 대해서 기본 로깅 설정 파일로 사용하므로 파일이 있는 경우 로딩하여 적용합니다. 따라서 아래 파일명을 사용하는 경우 운영 환경에서 별도의 로깅 설정을 적용할 때 문제가 발생할 수 있으므로 사용시 다양한 측면을 고려해야 합니다.

  • logback-spring.xml
  • logback.xml
  • logback-spring.groovy
  • logback.groovy

Logback XML 파일 작성하기

경고
title파일명 주의

Logback 설정 파일의 파일명을 logback.xml 파일로 사용하면 Spring Boot Application JAR 파일을 실행할 때 외부에서 옵션을 통해서 Logback 설정 파일을 변경하고자 하는 경우 적용되지 않을 수 있습니다. 따라서 Logback 설정 파일은 logback-local.xml 등의 파일명으로 변경해서 사용해야 합니다.

...