include/entropic/storage/audit_logger.h

← API

include/entropic/storage/audit_logger.h

entropic::AuditLogger

JSONL audit logger for MCP tool calls.

entropic::AuditLogger::AuditLogger(const AuditLogConfig &config)

Construct with configuration.

Parameters
  • config — Audit log configuration.

entropic::AuditLogger::~AuditLogger()

Destructor — flushes and closes the log file.

entropic::AuditLogger::AuditLogger(const AuditLogger &)=delete

AuditLogger & entropic::AuditLogger::operator=(const AuditLogger &)=delete

bool entropic::AuditLogger::initialize()

Open the log file and prepare for writing.

Opens audit.jsonl in the configured log_dir. If the file exists, new entries are APPENDED (not overwritten). The sequence counter starts at 0 for each new logger instance (it is monotonic per-session, not per-file).

Returns
true on success, false on I/O error.

void entropic::AuditLogger::record(const AuditEntry &entry)

Record a tool call audit entry.

Serializes the entry to JSON, adds session-level metadata (version, timestamp, session_id, sequence), and appends one line to the file. Thread-safe.

Parameters
  • entry — The audit log entry to write.

void entropic::AuditLogger::flush()

Force flush buffered entries to disk.

size_t entropic::AuditLogger::entry_count() const

Get the number of entries recorded this session.

Returns
Entry count.

std::filesystem::path entropic::AuditLogger::log_path() const

Get the file path of the current audit log.

Returns
Absolute path to audit.jsonl.

int entropic::AuditLogger::hook_callback(entropic_hook_point_t hook_point, const char *context_json, char **modified_json, void *user_data)

Hook callback for POST_TOOL_CALL integration.

Static callback registered with HookRegistry. Extracts fields from the hook context JSON and AuditHookContext (user_data), constructs an AuditEntry, and calls record(). Never modifies or cancels — sets *modified_json = NULL and returns 0.

Parameters
  • hook_point — Hook point (expected: ENTROPIC_HOOK_POST_TOOL_CALL).
  • context_json — JSON with tool_name, args, result, elapsed_ms.
  • modified_json out — Always set to NULL (no transformation).
  • user_data — Pointer to AuditHookContext.
  • hook_point — Hook point.
  • context_json — JSON with tool execution details.
  • modified_json out — Always NULL.
Returns
  • Always 0 (never cancels).
  • Always 0.