Sovite.Core.LogReader (sovite v0.6.0)

Copy Markdown View Source

Reads Sovite's own log lines back, for sovitectl trace and sovitectl report.

It understands every format Sovite writes (see docs/logging.md):

2026-10-04 12:00:00.123 [info] queue_id=4Xb2Kq event=queue.message.enqueued queue.message.enqueued: recipients=2, sender=a@example.com, size=1024
{"time":"2026-10-04T12:00:00.123456Z","level":"info","msg":"queue.message.enqueued: ...","queue_id":"4Xb2Kq","event":"queue.message.enqueued"}
Oct  4 12:00:00 mx1 sovite[812]: queue_id=4Xb2Kq event=queue.message.enqueued queue.message.enqueued: ...

and the same lines with a syslog or journald prefix. Each line becomes an entry with:

  • time - a NaiveDateTime, in the log's own time zone (the year of a classic syslog line is the current one), or nil
  • level - "info", "warning", ...
  • queue_id, session_id, remote_ip, event - the standard metadata, or nil
  • fields - the key=value pairs of a telemetry event's message, as strings
  • line - the line as it was

Lines that are not Sovite log lines are skipped. Gzip-compressed files (as logrotate leaves them) are read too.

Summary

Functions

The log files in directory written with file_name (a [log] file_name pattern), oldest first, compressed copies included.

Parses one log line, or returns nil if it is not a Sovite line.

Streams the entries of the log files at paths (oldest first), or of standard input for "-".

Types

entry()

@type entry() :: %{
  time: NaiveDateTime.t() | nil,
  level: String.t() | nil,
  queue_id: String.t() | nil,
  session_id: String.t() | nil,
  remote_ip: String.t() | nil,
  event: String.t() | nil,
  fields: %{optional(String.t()) => String.t()},
  line: String.t()
}

Functions

files(directory, file_name)

@spec files(Path.t(), String.t()) :: [Path.t()]

The log files in directory written with file_name (a [log] file_name pattern), oldest first, compressed copies included.

parse(line)

@spec parse(String.t()) :: entry() | nil

Parses one log line, or returns nil if it is not a Sovite line.

stream(paths)

@spec stream([Path.t()]) :: Enumerable.t(entry())

Streams the entries of the log files at paths (oldest first), or of standard input for "-".