class

Sepia::PerFileEventLogger

Inherits Sepia::EventLoggerBackend < Reference < Object

Event logging backend that stores one file per object.

This is the default implementation that creates a separate JSON Lines file for each object, containing all events for that object in chronological order.

File Structure

storage_path/
  ├── Document/   # Regular object storage
      └──.events/ # Event storage
      └── Document/
          └── doc - 123.jsonl # Events for doc-123

Event Format

Each line in the file is a JSON object:

{"ts":"2025-01-15T10:30:45Z","type":"created","gen":1,"meta":{}}
{"ts":"2025-01-15T11:15:22Z","type":"updated","gen":2,"meta":{"user":"alice"}}

Constructors

new(base_path : String = get_storage_path)
Source

Instance methods

append_event(object : Serializable | Container, event_type : LogEventType, generation : Int32, metadata)

Append an event to the object's event file.

Creates the event file and directory structure if needed, then appends the event as a JSON line.

Parameters

  • object : The Sepia object the event relates to
  • event_type : Type of event (Created, Updated, Deleted)
  • generation : Object generation number
  • metadata : Optional metadata for the event
Source
base_path

The base storage path for events.

This is automatically detected from the current storage backend.

Source
base_path=(base_path : String)

The base storage path for events.

This is automatically detected from the current storage backend.

Source
read_events(object_class : Class, id : String) : Array(LogEvent)

Read all events for a specific object from its event file.

Returns an empty array if the file doesn't exist or no events are found.

Parameters

  • object_class : The class of the object
  • id : The object's unique identifier

Returns

Array of events for the specified object, ordered by timestamp

Source