JsonEventSink.hpp

1. Overview

The JsonEventSink.hpp header declares the durable JSON-lines event sink used by RootGuard to append structured security events to the configured event log.

The file integrates the following components, APIs, or runtime concepts:

  • IEventSink – event callback contract
  • std::ofstream – append-only file stream
  • std::mutex – synchronization around event writes

2. Construction

The constructor accepts a filesystem path and opens the target event log. Failure to open the file is reported by the implementation as an exception at construction time.


3. Event Writing

onEvent() serializes one rg_event per line. A private escape() helper ensures C strings are JSON-safe.


4. Thread Safety

A private mutex protects the output stream, allowing multiple event-producing contexts to share the sink without interleaving JSON records.


5. Runtime and Security Considerations

  • Structured persistence: JSONL supports tailing and incremental parsing.
  • Logging failure isolation: event write failures are contained by the implementation so the security engine keeps running.