Class: RosettAi::Telemetry::JsonLinesWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/telemetry/json_lines_writer.rb

Overview

Writes telemetry events as JSON Lines (one JSON object per line).

Author:

  • hugo

  • claude

Instance Method Summary collapse

Constructor Details

#initialize(io:, rotator: nil) ⇒ JsonLinesWriter

Returns a new instance of JsonLinesWriter.

Parameters:

  • io (IO)

    output stream

  • rotator (LogRotator, nil) (defaults to: nil)

    optional log rotator for file output



17
18
19
20
# File 'lib/rosett_ai/telemetry/json_lines_writer.rb', line 17

def initialize(io:, rotator: nil)
  @io = io
  @rotator = rotator
end

Instance Method Details

#close

This method returns an undefined value.

Close the underlying IO.



33
34
35
# File 'lib/rosett_ai/telemetry/json_lines_writer.rb', line 33

def close
  @io.close unless @io == $stderr || @io == $stdout
end

#write(event_hash)

This method returns an undefined value.

Write a single event as a JSON line.

Parameters:

  • event_hash (Hash)

    event data (must be JSON-serializable)



26
27
28
29
# File 'lib/rosett_ai/telemetry/json_lines_writer.rb', line 26

def write(event_hash)
  rotate_if_needed
  @io.puts(JSON.generate(event_hash))
end