Skip to content

Commit 82356ec

Browse files
author
Mateusz
committed
Improve logging
1 parent 592fd6f commit 82356ec

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/core/common/logging_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ def __init__(
120120
) -> None:
121121
# Set default format if none provided - compact level, env tag, and PID
122122
if fmt is None:
123-
fmt = "%(asctime)s [%(levelname)s] [%(env_tag)s] [pid=%(process)d] %(name)s:%(lineno)d %(message)s"
123+
fmt = "%(asctime)s [%(levelname)s] [%(env_tag)s] [pid=%(process)d] [stream_id=%(stream_id)s] %(name)s:%(lineno)d %(message)s"
124124
super().__init__(fmt, datefmt, style=style)
125125

126+
def format(self, record: logging.LogRecord) -> str:
127+
"""Populate optional logging fields used by the global format."""
128+
if not hasattr(record, "stream_id"):
129+
record.stream_id = "-"
130+
return super().format(record)
131+
126132

127133
# Default set of fields to redact
128134
DEFAULT_REDACTED_FIELDS = {
@@ -564,7 +570,7 @@ def configure_logging_with_environment_tagging(
564570
"""
565571
# Use default format with environment tag if none provided - compact level, env tag, and PID
566572
if log_format is None:
567-
log_format = "%(asctime)s [%(levelname)s] [%(env_tag)s] [pid=%(process)d] %(name)s:%(lineno)d %(message)s"
573+
log_format = "%(asctime)s [%(levelname)s] [%(env_tag)s] [pid=%(process)d] [stream_id=%(stream_id)s] %(name)s:%(lineno)d %(message)s"
568574

569575
# Create formatter with environment tag support
570576
formatter = EnvironmentTaggingFormatter(fmt=log_format)

0 commit comments

Comments
 (0)