티스토리 뷰

SLF4J를 사용하던 중 junit 이나 spock을 이용해 테스트 코드를 작성했을 때 로그가 보이지 않는 경우가 발생한다.


SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/jhjeon/.m2/repository/org/slf4j/slf4j-nop/1.7.2/slf4j-nop-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/jhjeon/.m2/repository/org/slf4j/slf4j-log4j12/1.7.2/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.helpers.NOPLoggerFactory]


위의 error message에서 보듯이 여러개의 slf4j 라이브러리가 바인딩되어서 그렇다.

slf4j-nop는 NOP은 no-operation의 약어. 그러므로 logger 동작을 하지 않는다.

테스트 코드가 아니라 tomcat에서 구동됐을 때는 slf4j-log4j12-1.7.2.jar, slf4j-nop-1.7.2.jar 순으로 바인딩이 되어서 

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 와 같이 나타난다.



    org.slf4j
    slf4j-nop
    ${slf4j.version}


    org.slf4j
    slf4j-log4j12
    ${slf4j.version}


위의 maven 설정 중 slf4j-nop를 제거한다.


참고

http://www.slf4j.org/codes.html#multiple_bindings

http://www.slf4j.org/api/org/slf4j/helpers/NOPLogger.html



반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함