문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:slf4j [2013/07/22 16:35] kwon37xi [IntelliJ IDEA Slf4j Live Template] |
java:slf4j [2020/07/08 14:34] kwon37xi [Gradle 설정] |
||
---|---|---|---|
줄 4: | 줄 4: | ||
* Jakarta Commons Logging 과 비슷한 기능을 하지만 Slf4j가 더 좋다. | * Jakarta Commons Logging 과 비슷한 기능을 하지만 Slf4j가 더 좋다. | ||
* [[java: | * [[java: | ||
+ | |||
+ | ===== 의존성 ===== | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== 로거 객체 생성 ===== | ||
+ | <code java> | ||
+ | // 자동으로 현재 클래스를 찾아낸다. | ||
+ | import java.lang.invoke.MethodHandles; | ||
+ | |||
+ | private static final Logger logger = | ||
+ | LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
+ | </ | ||
===== Eclipse Slf4j Template ===== | ===== Eclipse Slf4j Template ===== | ||
줄 13: | 줄 26: | ||
* Abbreviation : '' | * Abbreviation : '' | ||
* Template Text : < | * Template Text : < | ||
- | private final org.slf4j.Logger | + | private final org.slf4j.Logger |
</ | </ | ||
* Edit variables | * Edit variables | ||
줄 23: | 줄 36: | ||
* Applicable in : **Java: declaration** | * Applicable in : **Java: declaration** | ||
- | {{: | + | {{: |
===== Legacy Logging Framework 제거하고 LogBack 사용 ===== | ===== Legacy Logging Framework 제거하고 LogBack 사용 ===== | ||
* http:// | * http:// | ||
줄 52: | 줄 66: | ||
configuration.exclude group: ' | configuration.exclude group: ' | ||
configuration.exclude group: ' | configuration.exclude group: ' | ||
+ | configuration.exclude group: ' | ||
configuration.exclude group: ' | configuration.exclude group: ' | ||
configuration.exclude group: ' | configuration.exclude group: ' | ||
줄 91: | 줄 106: | ||
</ | </ | ||
+ | ==== java.util.logging ==== | ||
+ | * http:// | ||
+ | * [[http:// | ||
+ | * [[springframework: | ||
+ | |||
+ | === SLF4JBridgeHandler 설정 === | ||
+ | * [[http:// | ||
+ | * 애플리케이션 시작 지점에 코드로 설정< | ||
+ | * // Optionally remove existing handlers attached to j.u.l root logger | ||
+ | | ||
+ | |||
+ | // add SLF4JBridgeHandler to j.u.l' | ||
+ | // the initialization phase of your application | ||
+ | | ||
+ | </ | ||
+ | * '' | ||
+ | handlers = org.slf4j.bridge.SLF4JBridgeHandler | ||
+ | </ | ||
+ | === Logback 설청 === | ||
+ | * '' | ||
+ | * groovy 설정< | ||
+ | import ch.qos.logback.classic.jul.LevelChangePropagator | ||
+ | context = new LevelChangePropagator() | ||
+ | context.resetJUL = true | ||
+ | </ | ||
+ | * XML 설정< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | .... | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Logger Wrapping ===== | ||
+ | * slf4j Logger를 사용할 때 특정 포맷으로 호출할 수 있게 Logger 호출을 감싸는 경우가 있는데, 이 때 log에 항상 로깅 위치가 Wrapper 코드로 남아서 실조 로그를 남기고자하는 코드 위치를 보기 불편해진다. | ||
+ | * '' | ||
+ | |||
+ | <code java> | ||
+ | private static final String FQCN = Logger.class.getName(); | ||
+ | |||
+ | |||
+ | public static void debug(String clazz, String message) { | ||
+ | org.slf4j.Logger logger = LoggerFactory.getLogger(clazz); | ||
+ | if (logger instanceof LocationAwareLogger) { | ||
+ | ((LocationAwareLogger) logger).log(null, | ||
+ | } else { | ||
+ | logger.debug(message); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Marker ===== | ||
+ | <code java> | ||
+ | Marker marker = MarkerFactory.getMarker(" | ||
+ | </ | ||
+ | |||
+ | * [[https:// | ||
+ | |||
+ | ===== SimpleLogger ===== | ||
+ | * [[http:// | ||
+ | <code java> | ||
+ | // 버전에 따라 프라퍼티 명이 simpleLogger가 아닌 simplelogger일 수도 있음. | ||
+ | // 버전에 따라 defaultLogLevel -> defaultlog 일 수도 있음. | ||
+ | System.setProperty(" | ||
+ | System.setProperty(" | ||
+ | </ | ||
+ | |||
+ | ===== Test Slf4j ===== | ||
+ | * [[http:// | ||
+ | |||
+ | ===== 참조 ===== | ||
+ | * [[https:// | ||