반응형
스프링 시큐리티를 배우던 중
@Log4j로 로그를 작성하는데 그동안 사용하던 log.info() 말고도 log.warn() 과 log.error() 도 있다는걸 알게됨
프로그램 개발 시 서비스가 동작하는 상태와 장애를 파악하는 것을 목적으로 로그를 작성
Apache log4j Level의 정의
ALL | The ALL has the lowest possible rank and is intended to turn on all logging. 가능한 가장 낮은 순위를 가지며 모든 로깅을 켜도록 되어있음 |
TRACE | The TRACE Level designates finer-grained informational events than the DEBUG. DEBUG 보다 세분화된 정보 이벤트를 지정 |
DEBUG | The DEBUG Level designates fine-grained informational events that are most useful to debug an application. 응용 프로그램을 디버깅하는 데 가장 유용한 세분화된 정보 이벤트를 지정 |
INFO | The INFO level designates informational messages that highlight the progress of the application at coarse-grained level. 응용 프로그램 진행률을 조잡한 수준에서 강조하는 정보 메시지 지정 |
WARN | The WARN level designates potentially harmful situations. 잠재적으로 유해한 상황을 나타냄 |
ERROR | The ERROR level designates error events that might still allow the application to continue running. 응용 프로그램이 계속 실행되도록 허용할 수 있는 오류 이벤트를 지정 |
FATAL | The FATAL level designates very severe error events that will presumably lead the application to abort. 응용 프로그램을 중단시킬 가능성이 있는 매우 심각한 오류 이벤트를 지정 |
OFF | The OFF has the highest possible rank and is intended to turn off logging. 가장 높은 순위를 가지며 로깅을 해제하도록 되어있음 |
위와 같은 단계를 가짐
예시
import org.apache.log4j.Level;
import lombok.extern.log4j.Log4j;
@Log4j
public class LogLevelTest {
public static void main(String[] args) {
log.setLevel(Level.INFO);
log.trace("Trace Message!");
log.debug("Debug Message!");
log.info("Info Message!");
log.warn("Warn Message!");
log.error("Error Message!");
log.fatal("Fatal Message!");
}
}
Level.INFO를 로그 레벨로 지정하면
INFO : test.test.test.LogLevelTest - Info Message!
WARN : test.test.test.LogLevelTest - Warn Message!
ERROR: test.test.test.LogLevelTest - Error Message!
FATAL: test.test.test.LogLevelTest - Fatal Message!
INFO 보다 높은 레벨만 로그로 찍히는 것을 볼 수 있음
'Spring' 카테고리의 다른 글
[Spring] 파일 업로드를 위한 form 태그 내부에 작성하는 enctype="multipart/form-data"의 의미 (0) | 2021.10.10 |
---|---|
[Spring] Spring Security 기본 세팅과 로그인, 로그아웃 로직 (0) | 2021.10.09 |
[Spring] Transaction(트랜잭션) (0) | 2021.10.07 |
[Spring] AOP(관점 지향 프로그래밍) (0) | 2021.10.06 |
[Spring] 크롬 확장 프로그램으로 REST 방식 테스트(Tomcat) (0) | 2021.10.03 |