Class LogFilterChain

java.lang.Object
cloud.opencode.base.log.filter.LogFilterChain

public final class LogFilterChain extends Object
Log Filter Chain - Ordered Chain of Log Filters 日志过滤器链 - 有序的日志过滤器链

Manages an ordered collection of LogFilter instances and evaluates them sequentially against a LogEvent. Filters are sorted by their LogFilter.getOrder() value (lower = higher priority).

管理 LogFilter 实例的有序集合,并按顺序对 LogEvent 进行评估。 过滤器按 LogFilter.getOrder() 值排序(较低 = 较高优先级)。

Features | 主要功能:

  • Thread-safe filter chain with copy-on-write semantics - 具有写时复制语义的线程安全过滤器链
  • Short-circuit on ACCEPT or DENY - 遇到 ACCEPT 或 DENY 时短路
  • Ordered filter evaluation - 有序的过滤器评估
  • Dynamic filter addition and removal - 动态添加和移除过滤器

Usage Examples | 使用示例:

LogFilterChain chain = new LogFilterChain();
chain.addFilter(new LevelFilter(LogLevel.WARN));
chain.addFilter(new ThrottleFilter(Duration.ofSeconds(5)));

FilterAction result = chain.apply(logEvent);
if (result != FilterAction.DENY) {
    // process the event
}

Security | 安全性:

  • Thread-safe: Yes (volatile + synchronized for mutations) - 线程安全: 是(volatile + synchronized 用于变更)
Since:
JDK 25, opencode-base-log V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • LogFilterChain

      public LogFilterChain()
  • Method Details

    • addFilter

      public void addFilter(LogFilter filter)
      Adds a filter to this chain, sorted by order. 向此链添加过滤器,按顺序排序。
      Parameters:
      filter - the filter to add | 要添加的过滤器
      Throws:
      NullPointerException - if filter is null | 如果过滤器为 null
    • removeFilter

      public void removeFilter(LogFilter filter)
      Removes a filter from this chain. 从此链中移除过滤器。
      Parameters:
      filter - the filter to remove | 要移除的过滤器
      Throws:
      NullPointerException - if filter is null | 如果过滤器为 null
    • apply

      public FilterAction apply(LogEvent event)
      Applies all filters in order to the given log event. 按顺序将所有过滤器应用于给定的日志事件。

      Evaluation stops on the first ACCEPT or DENY result. If all filters return NEUTRAL, this method returns NEUTRAL.

      评估在第一个 ACCEPT 或 DENY 结果时停止。如果所有过滤器都返回 NEUTRAL, 此方法返回 NEUTRAL。

      Parameters:
      event - the log event to evaluate | 要评估的日志事件
      Returns:
      the filter action | 过滤器动作
    • clear

      public void clear()
      Clears all filters from this chain. 清除此链中的所有过滤器。
    • getFilters

      public List<LogFilter> getFilters()
      Returns an unmodifiable view of the current filters. 返回当前过滤器的不可修改视图。
      Returns:
      unmodifiable list of filters | 不可修改的过滤器列表