class Sepia::PerFileEventLogger

Overview

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"}}

Defined in:

sepia/event_logger.cr

Constructors

Instance Method Summary

Instance methods inherited from class Sepia::EventLoggerBackend

append_event(object : Serializable | Container, event_type : LogEventType, generation : Int32, metadata) append_event, read_events(object_class : Class, id : String) : Array(LogEvent) read_events, should_log?(klass : Class) : Bool should_log?

Constructor Detail

def self.new(base_path : String = get_storage_path) #

[View source]

Instance Method Detail

def 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

[View source]
def base_path : String #

The base storage path for events.

This is automatically detected from the current storage backend.


[View source]
def base_path=(base_path : String) #

The base storage path for events.

This is automatically detected from the current storage backend.


[View source]
def 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


[View source]