4. Level 클래스
각 로그 메서드들은 자신만의 로그 레벨(Log level)을 가지고 있음
ex.
warning(), info()
로그 레벨이란 프로그램 운영 중에 발생되는 정보들을 위험도, 중요도 등에 따라 위계를 구분하여 관리하기 위해 사용되는 개념
이러한 로그 레벨은 Level 객체를 통해 관리됨
1. 로그 수준별 레벨의 구분
개별 로그 메시지는 기록 혹은 콘솔에 출력할 로그 내용이 가진 성격이나 해당 로그가 시스템에 미칠 수 있는 영향의 심각성에 따라 수준(Level)을 구분하여 출력할 수 있음
| 로그 레벨 | 의미 및 용도 | 심각도 분류 | 설명 |
|---|---|---|---|
ERROR | 즉시 조치가 필요한 오류, 시스템 기능 일부가 실패함 | 매우 심각 | 예: DB 연결 실패, 트랜잭션 실패, 예외로 인한 서비스 종료 등 |
WARNING | 정상 동작은 하나, 향후 문제를 야기할 수 있는 잠재적 위험 신호 | 주의 필요 | 예: 디스크 용량 부족 임박, 실패한 로그인 시도, 구성 파일 누락 등 |
INFO | 일반적인 입출력, 상태 변화, 이벤트에 대한 기록, 프로그램 동작에 문제는 없음 | 정보 용도 | 예: 사용자 로그인, 요청 수신, 정상적인 리소스 생성/삭제 |
DEBUG | 개발/디버깅용 상세 정보, 시스템 운영 중에는 보통 비활성화 | 개발 전용 | 예: 함수 진입/종료, 내부 변수 상태 등 |
TRACE | DEBUG보다 더 상세한 수준의 로그, 자세한 추적이 필요할 때 사용 | 개발 전용 | 예: 특정 조건 분기 내부 흐름 추적 |
2. java.util.logging의 로그 레벨
java.util.logging 라이브러리에서는 로깅할 메시지를 다음과 같은 수준 으로 구분하고 있음

각 Logger는 이러한 로그 레벨을 토대로 위계를 추적하여 지정된 수준보다 낮은 로깅 처리는 건너뛰게됨(skipping)
public void log(Level level, String msg) {
if (!isLoggable(level)) { // 로깅 허용 레벨이 아닐 경우 폐기
return;
}
LogRecord lr = new LogRecord(level, msg);
doLog(lr);
}위 이미지를 예로 들면,
로그와 관련된 환경 설정 정보(.xml or .properties 파일)에 로깅 레벨을 INFO로 설정해둘 경우,
그보다 하위 레벨인 CONFIG, FINE, FINER에 대한 로그 기록은 로깅 메시지로 생성되지 않음
1-2. 로깅 메시지 수준별 레벨 선정 기준
로깅 메시지의 수준별 레벨에 대한 선정 기준은 일반적으로 다음과 같으며, 팀에 따라 주관적일 수 있음
| 로그 레벨(Logging Level) | Description(설명) | Constant Value(상수값) |
|---|---|---|
| SEVERE | 치명적인 에러 | 1000 |
| WARNING | 치명적인 에러는 아니지만, 추후 잘못될 수 있는 경고 수준 | 900 |
| INFO | 일반적인 운영 기록, 사용자 로그인 기록 등 | 800 |
| CONFIG | 프로그램 설정 정보가 잘 동작하는지 확인하는 용도 | 700 |
| FINE | 시스템 동작을 추적(Trace)과 관련된 메시지 | 500 |
| FINER | FINE보다 상세한 추적 메시지 | 400 |
| FINEST | 가장 상세한 추적 메시지 | 300 |
정리하면,
로그 레벨이란 해당 프로그램이 운영 or 실행 중에 어느 수준까지 로그 메시지를 남길 것인지에 대한 정도를 나타내며, 이는 프로그램 실행 전에 개발자가 설정할 수 있음
로깅을 적절하게 사용하기
로그가 너무 적으면 시스템의 동작을 파악하기 어려울 수 있음
반대로 로그가 너무 많으면 불필요한 곳에서도 입출력에 따른 오버헤드가 발생하여 성능이 저하되는 원인이 될 수 있음
또한 비즈니스 로직이 로깅 메시지 코드와 뒤섞여 코드 가독성이 저하될 수 있음
→ 적절한 구간에 적절한 로그 메시지를 남기는 것이 중요
2. Level
java.util.logging에서는 이러한 로그의 수준을 Level 클래스를 통해 관리함
Level 객체는 Integer value 형태로 구분된 로그 레벨을 문자열 상수값 형태로 캡슐화해두었음
→ 숫자가 높을수록 높은 우선순위를 가지도록 설계된 상태
| 로그 레벨(Logging Level) | Constant Value(상수값) |
|---|---|
| SEVERE | 1000 |
| WARNING | 900 |
| INFO | 800 |
| CONFIG | 700 |
| FINE | 500 |
| FINER | 400 |
| FINEST | 300 |
로깅의 기본 설정값은 INFO 레벨 이상만 출력되도록 설정되어 있으며,
Level 클래스는 7개의 표준 로그 레벨을 정의해두었음
FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE
오른쪽으로 갈수록 높은 우선순위를 가짐
2-1. Level Class Summary
Level 클래스의 내부 구현 코드와 요약은 다음과 같음
public class Level implements java.io.Serializable {
/**
* @serial The non-localized name of the level.
* 로그 레벨의 이름
*/
private final String name;
/**
* @serial The integer value of the level.
* 각 레벨이 가진 정수형 숫자 값
*/
private final int value;
/**
* @serial The resource bundle name to be used in localizing the level name.
* 리소스 번들이름 - 주로 국제화(Localization)에서 사용되는 객체
*/
private final String resourceBundleName;
/**
* OFF is a special level that can be used to turn off logging.
* This level is initialized to <CODE>Integer.MAX_VALUE</CODE>.
* OFF - 로깅 처리를 비활성화 할 때 사용
*/
public static final Level OFF = new Level("OFF",Integer.MAX_VALUE, defaultBundle);
/**
* SEVERE is a message level indicating a serious failure.
* <p>
* In general SEVERE messages should describe events that are
* of considerable importance and which will prevent normal
* program execution. They should be reasonably intelligible
* to end users and to system administrators.
* This level is initialized to <CODE>1000</CODE>.
* SEVERE - 가장 심각한 수준의 내용을 로깅할 때 사용
*/
public static final Level SEVERE = new Level("SEVERE",1000, defaultBundle);
/**
* WARNING is a message level indicating a potential problem.
* <p>
* In general WARNING messages should describe events that will
* be of interest to end users or system managers, or which
* indicate potential problems.
* This level is initialized to <CODE>900</CODE>.
* WARNING - 잠재적인 문제가 발생할 수 있는 내용 로깅 시 사용
*/
public static final Level WARNING = new Level("WARNING", 900, defaultBundle);
/**
* INFO is a message level for informational messages.
* <p>
* Typically INFO messages will be written to the console
* or its equivalent. So the INFO level should only be
* used for reasonably significant messages that will
* make sense to end users and system administrators.
* This level is initialized to <CODE>800</CODE>.
* INFO - 일반적인 정보를 남기는 로깅 수행 시 사용
*/
public static final Level INFO = new Level("INFO", 800, defaultBundle);
/**
* CONFIG is a message level for static configuration messages.
* <p>
* CONFIG messages are intended to provide a variety of static
* configuration information, to assist in debugging problems
* that may be associated with particular configurations.
* For example, CONFIG message might include the CPU type,
* the graphics depth, the GUI look-and-feel, etc.
* This level is initialized to <CODE>700</CODE>.
* CONFIG - 정적인 설정 정보를 로깅할 때 사용
*/
public static final Level CONFIG = new Level("CONFIG", 700, defaultBundle);
/**
* FINE is a message level providing tracing information.
* <p>
* All of FINE, FINER, and FINEST are intended for relatively
* detailed tracing. The exact meaning of the three levels will
* vary between subsystems, but in general, FINEST should be used
* for the most voluminous detailed output, FINER for somewhat
* less detailed output, and FINE for the lowest volume (and
* most important) messages.
* <p>
* In general the FINE level should be used for information
* that will be broadly interesting to developers who do not have
* a specialized interest in the specific subsystem.
* <p>
* FINE messages might include things like minor (recoverable)
* failures. Issues indicating potential performance problems
* are also worth logging as FINE.
* This level is initialized to <CODE>500</CODE>.
* FINE, FINER, FINEST - 상세한 추적 정보 로깅 시 사용
*/
public static final Level FINE = new Level("FINE", 500, defaultBundle);
/**
* FINER indicates a fairly detailed tracing message.
* By default logging calls for entering, returning, or throwing
* an exception are traced at this level.
* This level is initialized to <CODE>400</CODE>.
*/
public static final Level FINER = new Level("FINER", 400, defaultBundle);
/**
* FINEST indicates a highly detailed tracing message.
* This level is initialized to <CODE>300</CODE>.
*/
public static final Level FINEST = new Level("FINEST", 300, defaultBundle);
/**
* ALL indicates that all messages should be logged.
* This level is initialized to <CODE>Integer.MIN_VALUE</CODE>.
* ALL - 모든 수준의 로그 기록 출력
*/
public static final Level ALL = new Level("ALL", Integer.MIN_VALUE, defaultBundle);
}