Interface AuditLogger


public interface AuditLogger
Audit Logger Interface - Audit Event Recording 审计记录器接口 - 审计事件记录

This interface defines the contract for audit logging implementations. Custom implementations can persist audit events to databases, files, or external systems.

此接口定义审计日志实现的契约。自定义实现可以将审计事件持久化到数据库、文件或外部系统。

Example | 示例:

public class DatabaseAuditLogger implements AuditLogger {
    @Override
    public void log(AuditEvent event) {
        auditRepository.save(event);
    }
}

AuditLog.setLogger(new DatabaseAuditLogger());

Features | 主要功能:

  • Pluggable audit event persistence - 可插拔的审计事件持久化
  • Enable/disable toggle - 启用/禁用开关
  • Lifecycle management (initialize/shutdown) - 生命周期管理(初始化/关闭)

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: No (event 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
    default void
    Initializes the audit logger.
    default boolean
    Checks if audit logging is enabled.
    void
    log(AuditEvent event)
    Logs an audit event.
    default void
    Shuts down the audit logger.
  • Method Details

    • log

      void log(AuditEvent event)
      Logs an audit event. 记录审计事件。
      Parameters:
      event - the audit event - 审计事件
    • isEnabled

      default boolean isEnabled()
      Checks if audit logging is enabled. 检查审计日志是否启用。
      Returns:
      true if enabled - 如果启用返回 true
    • initialize

      default void initialize()
      Initializes the audit logger. 初始化审计记录器。
    • shutdown

      default void shutdown()
      Shuts down the audit logger. 关闭审计记录器。