Class LevelFilter

java.lang.Object
cloud.opencode.base.log.filter.LevelFilter
All Implemented Interfaces:
LogFilter

public final class LevelFilter extends Object implements LogFilter
Level Filter - Filters Log Events by Threshold Level 级别过滤器 - 按阈值级别过滤日志事件

Denies log events with a level below the configured threshold. Events at or above the threshold pass through as NEUTRAL.

拒绝级别低于配置阈值的日志事件。 达到或超过阈值的事件以 NEUTRAL 通过。

Features | 主要功能:

  • Threshold-based level filtering - 基于阈值的级别过滤
  • DENY for below threshold, NEUTRAL for at or above - 低于阈值返回 DENY,达到或超过返回 NEUTRAL

Usage Examples | 使用示例:

// Only allow WARN and above
LevelFilter filter = new LevelFilter(LogLevel.WARN);
chain.addFilter(filter);

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-log V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • LevelFilter

      public LevelFilter(LogLevel threshold)
      Creates a level filter with the specified threshold. 使用指定阈值创建级别过滤器。
      Parameters:
      threshold - the minimum level to allow | 允许的最低级别
      Throws:
      NullPointerException - if threshold is null | 如果阈值为 null
  • Method Details

    • filter

      public FilterAction filter(LogEvent event)
      Filters the event based on its level. 根据事件级别进行过滤。
      Specified by:
      filter in interface LogFilter
      Parameters:
      event - the log event | 日志事件
      Returns:
      DENY if below threshold, NEUTRAL otherwise | 低于阈值返回 DENY,否则返回 NEUTRAL