Enum Class LogLevel

java.lang.Object
java.lang.Enum<LogLevel>
cloud.opencode.base.log.LogLevel
All Implemented Interfaces:
Serializable, Comparable<LogLevel>, Constable

public enum LogLevel extends Enum<LogLevel>
Log Level Enumeration - Defines Standard Log Levels 日志级别枚举 - 定义标准日志级别

This enum defines the standard log levels used throughout the logging framework. Levels are ordered by severity from TRACE (lowest) to OFF (highest).

此枚举定义日志框架中使用的标准日志级别。 级别按严重程度从 TRACE(最低)到 OFF(最高)排序。

Level Hierarchy | 级别层次:

TRACE (1) < DEBUG (2) < INFO (3) < WARN (4) < ERROR (5) < OFF (6)

Usage Guidelines | 使用指南:

  • TRACE - Fine-grained debug info, typically disabled - 细粒度调试信息,通常禁用
  • DEBUG - Debugging information - 调试信息
  • INFO - Informational messages - 信息性消息
  • WARN - Warning situations - 警告情况
  • ERROR - Error conditions - 错误情况
  • OFF - Turn off logging - 关闭日志

Features | 主要功能:

  • Six standard log levels from TRACE to OFF - 从 TRACE 到 OFF 的六个标准日志级别
  • Numeric level comparison - 数值级别比较
  • Case-insensitive parsing from name - 不区分大小写的名称解析
  • Safe parsing with default fallback - 安全解析,带默认回退

Usage Examples | 使用示例:

// Parse from name
LogLevel level = LogLevel.fromName("INFO");

// Compare levels
if (level.isGreaterOrEqual(LogLevel.WARN)) {
    // handle warning and above
}

// Safe parse with default
LogLevel level = LogLevel.fromNameOrDefault("UNKNOWN", LogLevel.INFO);

Security | 安全性:

  • Thread-safe: Yes (immutable enum) - 线程安全: 是(不可变枚举)
  • Null-safe: No (throws on null input) - 空值安全: 否(null 输入抛异常)
Since:
JDK 25, opencode-base-log V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Enum Constant Details

    • TRACE

      public static final LogLevel TRACE
      TRACE level - Most detailed information. TRACE 级别 - 最详细的信息。
    • DEBUG

      public static final LogLevel DEBUG
      DEBUG level - Debugging information. DEBUG 级别 - 调试信息。
    • INFO

      public static final LogLevel INFO
      INFO level - Informational messages. INFO 级别 - 信息性消息。
    • WARN

      public static final LogLevel WARN
      WARN level - Warning situations. WARN 级别 - 警告情况。
    • ERROR

      public static final LogLevel ERROR
      ERROR level - Error conditions. ERROR 级别 - 错误情况。
    • OFF

      public static final LogLevel OFF
      OFF level - Turn off logging. OFF 级别 - 关闭日志。
  • Method Details

    • values

      public static LogLevel[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static LogLevel valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getLevel

      public int getLevel()
      Returns the numeric level value. 返回数值级别。
      Returns:
      the level value - 级别数值
    • getName

      public String getName()
      Returns the level name. 返回级别名称。
      Returns:
      the level name - 级别名称
    • isGreaterOrEqual

      public boolean isGreaterOrEqual(LogLevel other)
      Checks if this level is greater than or equal to the specified level. 检查此级别是否大于或等于指定级别。
      Parameters:
      other - the other level to compare - 要比较的其他级别
      Returns:
      true if this level is greater than or equal to other - 如果此级别大于或等于其他级别则返回 true
    • isEnabledFor

      public boolean isEnabledFor(LogLevel threshold)
      Checks if this level is enabled for the specified threshold level. 检查此级别是否对指定阈值级别启用。
      Parameters:
      threshold - the threshold level - 阈值级别
      Returns:
      true if enabled - 如果启用则返回 true
    • fromName

      public static LogLevel fromName(String name)
      Parses a log level from its name. 从名称解析日志级别。
      Parameters:
      name - the level name (case-insensitive) - 级别名称(不区分大小写)
      Returns:
      the log level - 日志级别
      Throws:
      IllegalArgumentException - if the name is not valid - 如果名称无效
    • fromNameOrDefault

      public static LogLevel fromNameOrDefault(String name, LogLevel defaultLevel)
      Safely parses a log level from its name, returning a default if not found. 安全地从名称解析日志级别,如果未找到则返回默认值。
      Parameters:
      name - the level name - 级别名称
      defaultLevel - the default level - 默认级别
      Returns:
      the log level or default - 日志级别或默认值
    • toString

      public String toString()
      Overrides:
      toString in class Enum<LogLevel>