Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Improve comments in the structured logging code. (#10188)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored Jun 16, 2021
1 parent 76f9c70 commit 18edc9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/10188.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve comments in structured logging code.
9 changes: 5 additions & 4 deletions synapse/logging/_terse_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

_encoder = json.JSONEncoder(ensure_ascii=False, separators=(",", ":"))

# The properties of a standard LogRecord.
_LOG_RECORD_ATTRIBUTES = {
# The properties of a standard LogRecord that should be ignored when generating
# JSON logs.
_IGNORED_LOG_RECORD_ATTRIBUTES = {
"args",
"asctime",
"created",
Expand Down Expand Up @@ -59,9 +60,9 @@ def format(self, record: logging.LogRecord) -> str:
return self._format(record, event)

def _format(self, record: logging.LogRecord, event: dict) -> str:
# Add any extra attributes to the event.
# Add attributes specified via the extra keyword to the logged event.
for key, value in record.__dict__.items():
if key not in _LOG_RECORD_ATTRIBUTES:
if key not in _IGNORED_LOG_RECORD_ATTRIBUTES:
event[key] = value

return _encoder.encode(event)
Expand Down

0 comments on commit 18edc9a

Please sign in to comment.