Class: Browserctl::Trace::EventStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/browserctl/trace/event_stream.rb

Overview

Reads ‘cli.log` + `daemon.log` JSONL files from a log directory and yields records sorted by timestamp. Malformed lines are skipped silently — this matches the tolerant behaviour expected of `browserctl trace`.

Session filtering: when ‘session_filter` is provided, only records whose `session_id` matches are emitted. When nil, records are scoped to the most recent `session_id` observed in the merged stream (or all records if none carry a session id yet — backwards compatible with older logs).

Constant Summary collapse

LOG_GLOB =
"{cli,daemon}.log"

Instance Method Summary collapse

Constructor Details

#initialize(log_dir, session_filter: nil) ⇒ EventStream

Returns a new instance of EventStream.



20
21
22
23
# File 'lib/browserctl/trace/event_stream.rb', line 20

def initialize(log_dir, session_filter: nil)
  @log_dir = log_dir
  @session_filter = session_filter
end

Instance Method Details

#each(&block) ⇒ Object



25
26
27
28
29
# File 'lib/browserctl/trace/event_stream.rb', line 25

def each(&block)
  return enum_for(:each) unless block

  records.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/browserctl/trace/event_stream.rb', line 31

def empty?
  records.empty?
end

#recordsObject



35
36
37
# File 'lib/browserctl/trace/event_stream.rb', line 35

def records
  @records ||= filter_session(load_records)
end