Class AuditLogStorage

java.lang.Object
io.jenkins.plugins.auditlogger.AuditLogStorage

public class AuditLogStorage extends Object
Production-grade audit log storage. Design for heavy load: - Lock-free ConcurrentLinkedQueue for incoming events (zero blocking on callers) - Single daemon writer thread drains queue and writes batches - Persistent BufferedWriter (no open/close per entry) - Bounded in-memory ring buffer (ArrayDeque + ReadWriteLock) for UI/API queries - Automatic file rotation on size threshold - Proper shutdown with flush guarantee - Data masking integrated before persistence
  • Method Details

    • getInstance

      public static AuditLogStorage getInstance()
    • initialize

      public void initialize()
      Initialize storage: ensure dirs, load recent logs, start writer thread. Called once during plugin startup.
    • addEntry

      public void addEntry(AuditLogEntry entry)
      Record an audit event. Non-blocking — entry is queued for async disk write. Returns immediately; typical latency < 1 microsecond.
    • getAllEntries

      public List<AuditLogEntry> getAllEntries()
      Get all entries in memory (most recent MAX_ENTRIES_IN_MEMORY). Returns a defensive copy.
    • hasEntries

      public boolean hasEntries()
      Fast existence check used by the UI to avoid loading every entry during page render.
    • getAnomalyDetector

      public AnomalyDetector getAnomalyDetector()
      Get the anomaly detector instance for querying alerts.
    • flushNow

      public void flushNow()
      Force pending audit entries to be written immediately. Useful for events such as immediate restarts where the JVM may terminate before the scheduled writer thread gets its next flush window.
    • filterEntries

      public List<AuditLogEntry> filterEntries(String username, String action, Long startTime, Long endTime)
      Filter entries by criteria. Returns a defensive copy.
    • shutdown

      public void shutdown()
      Flush all pending writes and shut down the writer thread. Called on plugin stop.