From 013e79cd6bc3dff13b59913dc1a38334503c5031 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 20 Aug 2023 16:07:31 -0700 Subject: [PATCH] Add timestamps to log lines. --- voussoirkit/operatornotify.py | 9 ++++++++- voussoirkit/vlogging.py | 9 ++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/voussoirkit/operatornotify.py b/voussoirkit/operatornotify.py index d085987..285759e 100644 --- a/voussoirkit/operatornotify.py +++ b/voussoirkit/operatornotify.py @@ -249,7 +249,14 @@ def main_log_context(subject, level, **kwargs): log = vlogging.getLogger() handler = LogHandler(subject, **kwargs) handler.setLevel(level) - handler.setFormatter(vlogging.Formatter('{levelname}:{name}:{message}', style='{')) + datefmt = '%Y-%m-%dT%H:%M:%S' + formatter = vlogging.Formatter( + '[{asctime}.{msecs:03.0f}] {levelname}:{name}:{message}', + style='{', + datefmt=datefmt, + ) + formatter.default_msec_format = '%s.%03d' + handler.setFormatter(formatter) context = LogHandlerContext(log, handler) return context diff --git a/voussoirkit/vlogging.py b/voussoirkit/vlogging.py index e46bdb5..26cf1ed 100644 --- a/voussoirkit/vlogging.py +++ b/voussoirkit/vlogging.py @@ -54,12 +54,15 @@ def add_loud(log): def add_root_handler(level): handler = StreamHandler() + datefmt = '%Y-%m-%dT%H:%M:%S' if level <= LOUD: - handler.setFormatter(Formatter('{levelname}:{name}.{funcName}.{lineno}:{message}', style='{')) + formatter = Formatter('[{asctime}.{msecs:03.0f}] {levelname}:{name}.{funcName}.{lineno}:{message}', style='{', datefmt=datefmt) elif level <= DEBUG: - handler.setFormatter(Formatter('{levelname}:{name}.{funcName}:{message}', style='{')) + formatter = Formatter('[{asctime}.{msecs:03.0f}] {levelname}:{name}.{funcName}:{message}', style='{', datefmt=datefmt) else: - handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{')) + formatter = Formatter('[{asctime}.{msecs:03.0f}] {levelname}:{name}:{message}', style='{', datefmt=datefmt) + formatter.default_msec_format = '%s.%03d' + handler.setFormatter(formatter) handler.setLevel(level) root.addHandler(handler) return handler