Files
leleka/scripts/e2e/codex/tasks/debuglog-sched/seed/sched/logs.py
T

25 lines
700 B
Python

from .clock import format_ts
class Log:
"""Collects log lines stamped with the virtual clock."""
def __init__(self, clock, enabled=True):
self.clock = clock
self.enabled = enabled
self.lines = []
def _emit(self, level, comp, msg, args):
if self.enabled:
text = msg % args if args else msg
self.lines.append("%s %-5s %-8s %s" % (format_ts(self.clock.now()), level, comp, text))
def info(self, comp, msg, *args):
self._emit("INFO", comp, msg, args)
def warn(self, comp, msg, *args):
self._emit("WARN", comp, msg, args)
def error(self, comp, msg, *args):
self._emit("ERROR", comp, msg, args)