Permalink
Browse files

dict.get(item) vs dict[item] fixes the KeyError when you have a custo…

…m formatter variable and a logger did not include it.
  • Loading branch information...
1 parent 99512c8 commit 077aea25b8d8b0b8c65b263ec122cb50a9c3a807 @deanq deanq committed May 9, 2013
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/jsonlogger.py
View
@@ -94,10 +94,10 @@ def format(self, record):
log_record = {}
for field in self._required_fields:
- log_record[field] = record.__dict__[field]
+ log_record[field] = record.__dict__.get(field)
log_record.update(extras)
merge_record_extra(record, log_record, reserved=self._skip_fields)
return json.dumps(log_record,
default=self.json_default,
- cls=self.json_encoder)
+ cls=self.json_encoder)

0 comments on commit 077aea2

Please sign in to comment.