Merge pull request #15640 from ipapapa/feat/cleaner-logs

refactor(logger): Conditionally include extra_json in logs
This commit is contained in:
Tim Jaeryang Baek 2025-08-04 17:52:12 +04:00 committed by GitHub
commit 0b627248f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,12 +29,16 @@ def stdout_format(record: "Record") -> str:
Returns:
str: A formatted log string intended for stdout.
"""
record["extra"]["extra_json"] = json.dumps(record["extra"])
if record["extra"]:
record["extra"]["extra_json"] = json.dumps(record["extra"])
extra_format = " - {extra[extra_json]}"
else:
extra_format = ""
return (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level> - {extra[extra_json]}"
"<level>{message}</level>" + extra_format +
"\n{exception}"
)