Skip to Content
Suffering builds character
아카이브11.로깅특징8. Filter 인터페이스

8. Filter 인터페이스

1. Filter 인터페이스

Filter 인터페이스는 함수형 인터페이스로 설계되어 있음

Filter.java
@FunctionalInterface // 함수형 인터페이스 public interface Filter { /** Check if a given log record should be published. Params: record – a LogRecord Returns: true if the log record should be published 주어진 로그 레코드가 퍼블리싱되어야 하는지 확인 true일 경우 퍼블리싱됨 */ boolean isLoggable(LogRecord record); }

필터를 사용하면 로그 수준에서 제공하는 제어를 넘어 기록된 내용을 세밀하게 제어할 수 있음
개발자가 원하는 조건으로 커스터마이징하여 로깅 처리 여부를 필터링할 수 있도록 별도의 조건을 추가 가능한 인터페이스

각 Logger와 Handler는 필터를 연결할 수 있으며, Logger 또는 Handler는 isLoggable()을 호출하여 주어진 LogRecord를 출력해야 하는지 확인할 수 있음

만약 isLoggable이 false를 반환하면 LogRecord는 폐기됨

Logger.java
/** * Set a filter to control output on this Logger. * <P> * After passing the initial "level" check, the Logger will * call this Filter to check if a log record should really * be published. * * @param newFilter a filter object (may be null) * @throws SecurityException if a security manager exists, * this logger is not anonymous, and the caller * does not have LoggingPermission("control"). */ public void setFilter(Filter newFilter) throws SecurityException { checkPermission(); config.setFilter(newFilter); }

→ 특정 Logger 객체의 출력을 제어할 별도의 필터 객체를 설정하는 setter 메서드

초기 Level 체크를 통과한 후 로거는 이 필터를 호출하여 로그 레코드가 실제로 게시되어야 하는지 확인함

Last updated on