Skip to content

Commit

Permalink
Merge pull request #17 from Alsheh/logging-formatters-local
Browse files Browse the repository at this point in the history
Fixing an issue where numbers are considered valid JSON by the praser
  • Loading branch information
Alsheh authored May 5, 2021
2 parents 2a50bb3 + 5736268 commit b623852
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions supervisor/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,15 @@ def format(self, record):
else:
message = record.getMessage()
try:
message_dict = json.loads(message)
record.message = None
json_message = json.loads(message)
# The json parser accepts numbers as a valid json.
# But we want json objects only.
if isinstance(json_message, dict):
message_dict = json_message
record.message = None
else:
del json_message
record.message = as_string(message).rstrip('\n')
except json.decoder.JSONDecodeError:
record.message = as_string(message).rstrip('\n')

Expand Down

0 comments on commit b623852

Please sign in to comment.