Module: utils/runLogger

Shared logging and SSE helpers for pipeline modules.

Persists each log entry as an individual row in run_logs (ENH-008) and broadcasts via SSE for real-time frontend updates.

The legacy run.logs in-memory array is still populated so that in-flight SSE snapshots and any code that reads run.logs during an active run continues to work without modification. The array is no longer serialised to the runs.logs JSON column — the DB source of truth is run_logs.

Level-specific helpers

Function Level Icon UI colour
log(run, msg) info gray
logWarn warn ⚠️ amber
logError error red
logSuccess info green

Exports

  • log, logWarn, logError, logSuccess
  • emitRunEvent — Lazy-loaded SSE emitter (avoids circular imports).
  • ICON — Centralised icon prefix constants.
Source:

Methods

(static) log(run, msg, levelopt)

Append a timestamped log entry to the run_logs table, print to stdout, and broadcast via SSE so the frontend live-log updates in real time.

The entry stored in run_logs (and sent to the frontend) uses a compact format: [timestamp] message (timestamp format driven by LOG_DATE_FORMAT)

The server stdout line uses the full formatLogLine() output which includes log level, run ID, and respects LOG_JSON mode: [2025-04-03T12:34:56.789Z] [INFO ] [RUN-42] Starting crawl — or in JSON mode — {"ts":"...","level":"info","runId":"RUN-42","msg":"Starting crawl"}

The in-memory run.logs array is still appended to for backwards compatibility with any code that reads it during an active run. It is no longer the persistent store — run_logs rows are the source of truth.

Parameters:
Name Type Attributes Default Description
run object

— mutable run record (must have .id and .logs[])

msg string

— human-readable log message

level "debug" | "info" | "warn" | "error" <optional>
"info"

— severity level

Source:

(static) logError()

Log an error — prefixes with ❌, level "error".

Source:

(static) logSuccess()

Log a success — prefixes with ✅, level "info".

Source:

(static) logWarn()

Log a warning — prefixes with ⚠️, level "warn".

Source: