본문 바로가기

java

Spring Boot Log4j2 기본설정

참고

https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#core-properties

 

Common Application properties

 

docs.spring.io

https://docs.spring.io/spring-boot/docs/2.2.0.RELEASE/reference/html/spring-boot-features.html#boot-features-logging

 

Spring Boot Features

If you need to call remote REST services from your application, you can use the Spring Framework’s RestTemplate class. Since RestTemplate instances often need to be customized before being used, Spring Boot does not provide any single auto-configured Res

docs.spring.io

 

스프링 부트 log4j2 적용

 

 

log4j2 디펜던시만 추가하여도 application-properties에서 옵션 설정만으로 사용이 가능하다

아무것도 설정하지 않아도 기본 디폴트 값이 지정되어있음(관련 설정은 상단 프로퍼티 링크 참고) 

 

 

 

 

 

 

 

하지만 한가지 문재가 발생 하단 링크 참조

https://stackoverflow.com/questions/14024756/slf4j-class-path-contains-multiple-slf4j-bindings

 

SLF4J: Class path contains multiple SLF4J bindings

I'm getting the following error. It seems there are multiple logging frameworks bound to slf4j. Not sure how to resolve this. Any help is greatly appreciated. SLF4J: Class path contains multiple SL...

stackoverflow.com

 

스프링 부트는 spring-boot-starter로 시작하는 디펜던시에 logback과 의존관계가 형성 되어 있어 부트 실행시StaticLoggerBinder.class 중복 바인딩 오류가 발생한다.( 둘중 하나를 통해 로그가 출력되긴 하는 것 같다 )

아래처럼 예외 처리 해주면 해결된다. (spring-boot-starter-* 시작하는 것 중 하나)