Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Alog Petty Print to prepend Metadata #451

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/python/alog/alog.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ class AlogPrettyFormatter(AlogFormatterBase):
"debug4": "DBG4",
}

def __init__(self, channel_len=5) -> None:
def __init__(self, channel_len=5, include_metadata: bool = False) -> None:
AlogFormatterBase.__init__(self)
self.channel_len = channel_len
self.include_metadata = include_metadata

def _make_header(
self, timestamp: str, channel: str, level: str, log_code: Optional[str]
Expand Down Expand Up @@ -270,10 +271,11 @@ def format(self, record: logging.LogRecord) -> str:
# Add metadata if present
if not hasattr(record, "message"):
record.message = ""
if metadata is not None and len(metadata) > 0:
if self.include_metadata and metadata is not None and len(metadata) > 0:
if len(record.message) > 0:
record.message += " "
record.message += json.dumps(metadata)
record.message = json.dumps(metadata)+" "+record.message
else:
record.message = json.dumps(metadata)

level = record.levelname
channel = record.name
Expand Down