Class SlowOperationConfig

java.lang.Object
cloud.opencode.base.log.perf.SlowOperationConfig

public final class SlowOperationConfig extends Object
Slow Operation Config - Configuration for Slow Operation Detection 慢操作配置 - 慢操作检测配置

This class defines the configuration for detecting and logging slow operations. It allows setting thresholds, log levels, and optional stack trace inclusion.

此类定义检测和记录慢操作的配置。它允许设置阈值、日志级别和可选的堆栈跟踪包含。

Example | 示例:

SlowOperationConfig config = SlowOperationConfig.builder()
    .threshold(Duration.ofMillis(500))
    .logLevel(LogLevel.WARN)
    .includeStackTrace(true)
    .build();

PerfLog.setSlowOperationConfig(config);

Features | 主要功能:

  • Configurable slow operation threshold - 可配置的慢操作阈值
  • Configurable log level for slow operations - 可配置的慢操作日志级别
  • Optional stack trace inclusion - 可选的堆栈跟踪包含
  • Enable/disable toggle - 启用/禁用开关

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: No (throws on null threshold/logLevel) - 空值安全: 否(null 阈值/日志级别抛异常)
Since:
JDK 25, opencode-base-log V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

    • DEFAULT_THRESHOLD

      public static final Duration DEFAULT_THRESHOLD
      Default threshold: 1 second
    • DEFAULT_LOG_LEVEL

      public static final LogLevel DEFAULT_LOG_LEVEL
      Default log level: WARN
    • DEFAULT

      public static final SlowOperationConfig DEFAULT
      Default config instance
  • Method Details

    • getThreshold

      public Duration getThreshold()
      Returns the slow operation threshold. 返回慢操作阈值。
      Returns:
      the threshold - 阈值
    • getThresholdMillis

      public long getThresholdMillis()
      Returns the threshold in milliseconds. 返回以毫秒为单位的阈值。
      Returns:
      threshold in milliseconds - 毫秒阈值
    • getLogLevel

      public LogLevel getLogLevel()
      Returns the log level for slow operations. 返回慢操作的日志级别。
      Returns:
      the log level - 日志级别
    • isIncludeStackTrace

      public boolean isIncludeStackTrace()
      Returns whether to include stack trace. 返回是否包含堆栈跟踪。
      Returns:
      true to include stack trace - 如果包含堆栈跟踪返回 true
    • isEnabled

      public boolean isEnabled()
      Returns whether slow operation detection is enabled. 返回慢操作检测是否启用。
      Returns:
      true if enabled - 如果启用返回 true
    • isSlow

      public boolean isSlow(long elapsedMillis)
      Checks if the elapsed time exceeds the threshold. 检查耗时是否超过阈值。
      Parameters:
      elapsedMillis - the elapsed time in milliseconds - 毫秒耗时
      Returns:
      true if slow - 如果慢返回 true
    • builder

      public static SlowOperationConfig.Builder builder()
      Creates a new builder. 创建新的构建器。
      Returns:
      the builder - 构建器
    • toString

      public String toString()
      Overrides:
      toString in class Object