ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
file_log_exporter Class Referencefinal

Exports log records to a JSON Lines file. More...

#include <file_log_exporter.hpp>

Inheritance diagram for file_log_exporter:
Inheritance graph
Collaboration diagram for file_log_exporter:
Collaboration graph

Public Member Functions

 file_log_exporter (const std::filesystem::path &path)
 Constructs a file log exporter.
 
void export_record (domain::log_record record) override
 Exports a log record as a JSON line.
 
void flush () override
 Flushes the file stream.
 
void shutdown () override
 Closes the file.
 

Detailed Description

Exports log records to a JSON Lines file.

Each log record is written as a single JSON object on its own line, following the JSON Lines format (https://jsonlines.org/). This format is ideal for log shipping tools like Filebeat or Fluent Bit.

Example output:

{"timestamp":"2025-01-15T10:30:45.123Z","severity":"INFO","body":"Starting..."}
{"timestamp":"2025-01-15T10:30:45.456Z","severity":"DEBUG","body":"Connected"}

Thread-safety: This class is thread-safe. Multiple threads can call export_record() concurrently.

Constructor & Destructor Documentation

◆ file_log_exporter()

file_log_exporter ( const std::filesystem::path &  path)
explicit

Constructs a file log exporter.

Parameters
pathPath to the output file. Will be created if it doesn't exist.
Exceptions
std::runtime_errorif the file cannot be opened.

Member Function Documentation

◆ export_record()

void export_record ( domain::log_record  record)
overridevirtual

Exports a log record as a JSON line.

The record is immediately written to the file (no internal buffering beyond OS-level buffering).

Parameters
recordThe log record to export.

Implements log_exporter.

◆ flush()

void flush ( )
overridevirtual

Flushes the file stream.

Implements log_exporter.

◆ shutdown()

void shutdown ( )
overridevirtual

Closes the file.

Implements log_exporter.