Class OpenLog

java.lang.Object
cloud.opencode.base.log.OpenLog

public final class OpenLog extends Object
OpenLog - Unified Logging Facade OpenLog - 统一日志门面

This is the main entry point for the OpenCode logging framework. It provides static methods for all logging operations with zero configuration.

这是 OpenCode 日志框架的主入口点。它提供零配置的所有日志操作的静态方法。

Features | 特性:

  • Static facade methods - 静态门面方法
  • Automatic caller class detection - 自动调用类检测
  • Lambda lazy evaluation - Lambda 延迟求值
  • Parameterized logging with {} - 使用 {} 的参数化日志
  • Marker support - 标记支持
  • Exception logging - 异常日志

Example | 示例:

// Simple logging
OpenLog.info("Application started");

// Parameterized logging
OpenLog.info("User {} logged in from {}", userId, ipAddress);

// Lambda lazy evaluation
OpenLog.debug(() -> "Expensive: " + computeValue());

// Exception logging
OpenLog.error("Operation failed", exception);

// Get Logger instance
Logger log = OpenLog.get(MyClass.class);

Security | 安全性:

  • Thread-safe: Yes (stateless static facade) - 线程安全: 是(无状态静态门面)
  • Null-safe: No (message must not be null) - 空值安全: 否(消息不能为 null)
Since:
JDK 25, opencode-base-log V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    debug(String message)
    Logs a message at DEBUG level.
    static void
    debug(String format, Object... args)
    Logs a message at DEBUG level with parameters.
    static void
    debug(Supplier<String> messageSupplier)
    Logs a message at DEBUG level using lazy evaluation.
    static void
    error(Marker marker, String message, Throwable throwable)
    Logs a message at ERROR level with a marker and exception.
    static void
    error(String message)
    Logs a message at ERROR level.
    static void
    error(String format, Object... args)
    Logs a message at ERROR level with parameters.
    static void
    error(String message, Throwable throwable)
    Logs a message at ERROR level with an exception.
    static void
    error(Throwable throwable)
    Logs an exception at ERROR level.
    static void
    error(Supplier<String> messageSupplier, Throwable throwable)
    Logs a message at ERROR level using lazy evaluation with exception.
    static Logger
    get()
    Gets a logger for the calling class.
    static Logger
    get(Class<?> clazz)
    Gets a logger for the specified class.
    static Logger
    get(String name)
    Gets a logger for the specified name.
    static void
    info(Marker marker, String message)
    Logs a message at INFO level with a marker.
    static void
    info(String message)
    Logs a message at INFO level.
    static void
    info(String format, Object... args)
    Logs a message at INFO level with parameters.
    static void
    info(Supplier<String> messageSupplier)
    Logs a message at INFO level using lazy evaluation.
    static boolean
    Checks if DEBUG level is enabled.
    static boolean
    Checks if ERROR level is enabled.
    static boolean
    Checks if INFO level is enabled.
    static boolean
    Checks if TRACE level is enabled.
    static boolean
    Checks if WARN level is enabled.
    static void
    trace(String message)
    Logs a message at TRACE level.
    static void
    trace(String format, Object... args)
    Logs a message at TRACE level with parameters.
    static void
    trace(Supplier<String> messageSupplier)
    Logs a message at TRACE level using lazy evaluation.
    static void
    warn(String message)
    Logs a message at WARN level.
    static void
    warn(String format, Object... args)
    Logs a message at WARN level with parameters.
    static void
    warn(String message, Throwable throwable)
    Logs a message at WARN level with an exception.
    static void
    warn(Supplier<String> messageSupplier)
    Logs a message at WARN level using lazy evaluation.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public static Logger get()
      Gets a logger for the calling class. 获取调用类的日志记录器。
      Returns:
      the logger instance - 日志记录器实例
    • get

      public static Logger get(Class<?> clazz)
      Gets a logger for the specified class. 获取指定类的日志记录器。
      Parameters:
      clazz - the class - 类
      Returns:
      the logger instance - 日志记录器实例
    • get

      public static Logger get(String name)
      Gets a logger for the specified name. 获取指定名称的日志记录器。
      Parameters:
      name - the logger name - 日志记录器名称
      Returns:
      the logger instance - 日志记录器实例
    • trace

      public static void trace(String message)
      Logs a message at TRACE level. 在 TRACE 级别记录消息。
      Parameters:
      message - the message - 消息
    • trace

      public static void trace(String format, Object... args)
      Logs a message at TRACE level with parameters. 在 TRACE 级别记录带参数的消息。
      Parameters:
      format - the format string - 格式字符串
      args - the arguments - 参数
    • trace

      public static void trace(Supplier<String> messageSupplier)
      Logs a message at TRACE level using lazy evaluation. 使用延迟求值在 TRACE 级别记录消息。
      Parameters:
      messageSupplier - the message supplier - 消息提供者
    • debug

      public static void debug(String message)
      Logs a message at DEBUG level. 在 DEBUG 级别记录消息。
      Parameters:
      message - the message - 消息
    • debug

      public static void debug(String format, Object... args)
      Logs a message at DEBUG level with parameters. 在 DEBUG 级别记录带参数的消息。
      Parameters:
      format - the format string - 格式字符串
      args - the arguments - 参数
    • debug

      public static void debug(Supplier<String> messageSupplier)
      Logs a message at DEBUG level using lazy evaluation. 使用延迟求值在 DEBUG 级别记录消息。
      Parameters:
      messageSupplier - the message supplier - 消息提供者
    • info

      public static void info(String message)
      Logs a message at INFO level. 在 INFO 级别记录消息。
      Parameters:
      message - the message - 消息
    • info

      public static void info(String format, Object... args)
      Logs a message at INFO level with parameters. 在 INFO 级别记录带参数的消息。
      Parameters:
      format - the format string - 格式字符串
      args - the arguments - 参数
    • info

      public static void info(Supplier<String> messageSupplier)
      Logs a message at INFO level using lazy evaluation. 使用延迟求值在 INFO 级别记录消息。
      Parameters:
      messageSupplier - the message supplier - 消息提供者
    • info

      public static void info(Marker marker, String message)
      Logs a message at INFO level with a marker. 使用标记在 INFO 级别记录消息。
      Parameters:
      marker - the marker - 标记
      message - the message - 消息
    • warn

      public static void warn(String message)
      Logs a message at WARN level. 在 WARN 级别记录消息。
      Parameters:
      message - the message - 消息
    • warn

      public static void warn(String format, Object... args)
      Logs a message at WARN level with parameters. 在 WARN 级别记录带参数的消息。
      Parameters:
      format - the format string - 格式字符串
      args - the arguments - 参数
    • warn

      public static void warn(String message, Throwable throwable)
      Logs a message at WARN level with an exception. 在 WARN 级别记录带异常的消息。
      Parameters:
      message - the message - 消息
      throwable - the exception - 异常
    • warn

      public static void warn(Supplier<String> messageSupplier)
      Logs a message at WARN level using lazy evaluation. 使用延迟求值在 WARN 级别记录消息。
      Parameters:
      messageSupplier - the message supplier - 消息提供者
    • error

      public static void error(String message)
      Logs a message at ERROR level. 在 ERROR 级别记录消息。
      Parameters:
      message - the message - 消息
    • error

      public static void error(String format, Object... args)
      Logs a message at ERROR level with parameters. 在 ERROR 级别记录带参数的消息。
      Parameters:
      format - the format string - 格式字符串
      args - the arguments - 参数
    • error

      public static void error(String message, Throwable throwable)
      Logs a message at ERROR level with an exception. 在 ERROR 级别记录带异常的消息。
      Parameters:
      message - the message - 消息
      throwable - the exception - 异常
    • error

      public static void error(Throwable throwable)
      Logs an exception at ERROR level. 在 ERROR 级别记录异常。
      Parameters:
      throwable - the exception - 异常
    • error

      public static void error(Supplier<String> messageSupplier, Throwable throwable)
      Logs a message at ERROR level using lazy evaluation with exception. 使用延迟求值和异常在 ERROR 级别记录消息。
      Parameters:
      messageSupplier - the message supplier - 消息提供者
      throwable - the exception - 异常
    • error

      public static void error(Marker marker, String message, Throwable throwable)
      Logs a message at ERROR level with a marker and exception. 使用标记和异常在 ERROR 级别记录消息。
      Parameters:
      marker - the marker - 标记
      message - the message - 消息
      throwable - the exception - 异常
    • isTraceEnabled

      public static boolean isTraceEnabled()
      Checks if TRACE level is enabled. 检查 TRACE 级别是否启用。
      Returns:
      true if enabled - 如果启用返回 true
    • isDebugEnabled

      public static boolean isDebugEnabled()
      Checks if DEBUG level is enabled. 检查 DEBUG 级别是否启用。
      Returns:
      true if enabled - 如果启用返回 true
    • isInfoEnabled

      public static boolean isInfoEnabled()
      Checks if INFO level is enabled. 检查 INFO 级别是否启用。
      Returns:
      true if enabled - 如果启用返回 true
    • isWarnEnabled

      public static boolean isWarnEnabled()
      Checks if WARN level is enabled. 检查 WARN 级别是否启用。
      Returns:
      true if enabled - 如果启用返回 true
    • isErrorEnabled

      public static boolean isErrorEnabled()
      Checks if ERROR level is enabled. 检查 ERROR 级别是否启用。
      Returns:
      true if enabled - 如果启用返回 true