2021-07-07 강의록_Log4j(2) 로그 레벨

MIN.DI·2021년 7월 7일
0

강의록

목록 보기
30/54

  • Log4j / Log4j2 log level 정리

=================================================================================

@Log4j

=================================================================================
maven(web.xml)에 아래 dependency 추가해야 함

<!-- log4j -->
<dependency>
	<groupId>log4j</groupId>
	<artifactId>log4j</artifactId>
	<version>1.2.17</version>
</dependency>

=================================================================================

@Log4j2

=================================================================================
maven(web.xml)에 아래 dependency 추가해야 함

<!-- log4j-core -->
<dependency>
	<groupId>org.apache.logging.log4j</groupId>
	<artifactId>log4j-core</artifactId>
	<version>2.14.1</version>
</dependency>

=================================================================================
log.fatal("fatal"); //치명적인 로그
log.error("error"); //논리적인 오류, 비즈니스 로직 상 나와선 안 될 결과가 나온 경우
////////////////// 위의 두 레벨은 Consol창에 빨간색으로 찍힘

log.warn("warn"); //경고성 메시지
log.info("info"); //가장 일반적인 로그 (단순 정보성 로그)
log.debug("debug"); //더 상세하게 찍는 로그
log.trace("trace"); //가장 상세하게 찍는 로그

=================================================================================

// 로그레벨 지정 >> 남긴 로그 중 보고싶은 레벨까지만 볼 수 있다.

Level.OFF : 0 : X
Level.FATAL : 0 : fatal
Level.ERROR : 3 : fatal, error
Level.WARN : 4 : fatal, error, warn
Level.INFO : 6 : fatal, error, warn, info
Level.DEBUG : 7 : fatal, error, warn, info, debug
Level.TRACE : 7 : fatal, error, warn, info, debug, trace
Level.ALL : 7 : fatal, error, warn, info, debug, trace

=================================================================================

// Highest possible rank, to turn off logging.
log.setLevel(Level.OFF); // 0

// Very severe error events that will presumably lead the application to abort.
log.setLevel(Level.FATAL); // 0 - fatal

// Error events that might still allow the application to continue running.
log.setLevel(Level.ERROR); // 3 - fatal, error

// Potentially harmful situations.
log.setLevel(Level.WARN); // 4 - fatal, error, warn

// Informational messages that highlight the progress of the application at coarse-grained level.
log.setLevel(Level.INFO); // 6 - fatal, error, warn, info

// Fine-grained informational events that are most useful to debug an application.
log.setLevel(Level.DEBUG); // 7 - fatal, error, warn, info, debug

// Finer-grained informational events than the DEBUG level.
log.setLevel(Level.TRACE); // 7 - fatal, error, warn, info, debug, trace

// The lowest possible rank and is intended to turn on all logging.
log.setLevel(Level.ALL); // 7 - fatal, error, warn, info, debug, trace

=================================================================================

profile
내가 보려고 쓰는 블로그

0개의 댓글

관련 채용 정보