Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::AuditLogger Class Reference

JSONL audit logger for MCP tool calls. More...

#include <entropic/storage/audit_logger.h>

Public Member Functions

 AuditLogger (const AuditLogConfig &config)
 Construct with configuration.
 
 ~AuditLogger ()
 Destructor — flushes and closes the log file.
 
 AuditLogger (const AuditLogger &)=delete
 
AuditLoggeroperator= (const AuditLogger &)=delete
 
bool initialize ()
 Open the log file and prepare for writing.
 
void record (const AuditEntry &entry)
 Record a tool call audit entry.
 
void flush ()
 Force flush buffered entries to disk.
 
size_t entry_count () const
 Get the number of entries recorded this session.
 
std::filesystem::path log_path () const
 Get the file path of the current audit log.
 

Static Public Member Functions

static int 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.
 

Detailed Description

JSONL audit logger for MCP tool calls.

Writes one JSON line per tool execution to audit.jsonl. Thread-safe via write_mutex_. Atomic sequence counter ensures total ordering even under concurrent writes.

Lifecycle:
AuditLogger logger(config);
logger.initialize();
logger.record(entry);
logger.flush();
// Destructor flushes and closes
JSONL audit logger for MCP tool calls.
Thread safety:
record() and flush() acquire write_mutex_. Multiple threads can call record() concurrently without corruption.
Version
1.9.5

Definition at line 53 of file audit_logger.h.

Constructor & Destructor Documentation

◆ AuditLogger()

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

Construct with configuration.

Parameters
configAudit log configuration.
Version
1.9.5

Definition at line 27 of file audit_logger.cpp.

◆ ~AuditLogger()

entropic::AuditLogger::~AuditLogger ( )

Destructor — flushes and closes the log file.

Version
1.9.5

Definition at line 34 of file audit_logger.cpp.

Member Function Documentation

◆ entry_count()

size_t entropic::AuditLogger::entry_count ( ) const

Get the number of entries recorded this session.

Returns
Entry count.
Version
1.9.5
Returns
Entry count.

Definition at line 128 of file audit_logger.cpp.

◆ flush()

void entropic::AuditLogger::flush ( )

Force flush buffered entries to disk.

Version
1.9.5

Definition at line 114 of file audit_logger.cpp.

◆ hook_callback()

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

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_pointHook point (expected: ENTROPIC_HOOK_POST_TOOL_CALL).
context_jsonJSON with tool_name, args, result, elapsed_ms.
[out]modified_jsonAlways set to NULL (no transformation).
user_dataPointer to AuditHookContext.
Returns
Always 0 (never cancels). @callback
Version
1.9.5
Parameters
hook_pointHook point.
context_jsonJSON with tool execution details.
[out]modified_jsonAlways NULL.
user_dataPointer to AuditHookContext.
Returns
Always 0. @callback
Version
1.9.5

Definition at line 210 of file audit_logger.cpp.

◆ initialize()

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.
Version
1.9.5
Returns
true on success, false on I/O error.

Definition at line 48 of file audit_logger.cpp.

◆ log_path()

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

Get the file path of the current audit log.

Returns
Absolute path to audit.jsonl.
Version
1.9.5
Returns
Absolute path to audit.jsonl.

Definition at line 138 of file audit_logger.cpp.

◆ record()

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
entryThe audit log entry to write.
Version
1.9.5
Parameters
entryThe audit log entry to write.

Definition at line 72 of file audit_logger.cpp.


The documentation for this class was generated from the following files: