Class AuditFileSink

java.lang.Object
org.mockserver.mock.audit.AuditFileSink

public class AuditFileSink extends Object
Optional, durable NDJSON file sink for control-plane AuditEntry records.

The in-memory AuditStore ring buffer is deliberately volatile — it is bounded and is wiped by the very reset it records. This sink is a separate optional writer that observes the same entries as they are recorded and appends one JSON object per line ("newline-delimited JSON") to a file, giving a tamper-evident, restart-surviving audit trail. It never reads from or mutates the ring buffer — the ring stays exactly as-is, honouring the AuditEntry contract that the in-memory store must never "become a sink".

Configured by the mockserver.auditLogFile property (empty default = off, behaviour unchanged). The path is resolved once, on the first entry written (fixed thereafter, mirroring AuditStore's fixed-at-first-read capacity). All write and open failures are handled by logging a single WARN and disabling the sink — an IO error here must never crash request handling. Rotation is out of scope: the file grows append-only; use external log rotation (e.g. logrotate) or a bounded controlPlaneAuditMaxEntries + periodic archival if needed.

  • Method Details

    • getInstance

      public static AuditFileSink getInstance()
    • write

      public void write(AuditEntry entry, String configuredPath)
      Appends entry as a single NDJSON line to the configured audit log file, flushing per line. A no-op when configuredPath is blank, or once the sink has been disabled by an earlier IO error. Never throws.
      Parameters:
      entry - the audit entry to persist (also held in the in-memory store)
      configuredPath - the target file path; resolved once on first call and fixed thereafter