Closed
Bug 901788
Opened 11 years ago
Closed 11 years ago
Mozlog's json formatter should populate defaults for unstructured callers
Categories
(Testing :: Mozbase, defect)
Testing
Mozbase
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: chmanchester, Assigned: chmanchester)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
To support python logging clients that use the usual interface to the logger (i.e. not log_structured), such as those currently in our python harnesses, mozlog's json formatter should be able to emit a json message populated with defaults taken from the logger's own metadata.
Assignee | ||
Updated•11 years ago
|
Attachment #786080 -
Flags: review?(ahalberstadt)
Comment 1•11 years ago
|
||
Comment on attachment 786080 [details] [diff] [review] Allow mozlog's json formatter to output messages originating from unstructured callers. Review of attachment 786080 [details] [diff] [review]: ----------------------------------------------------------------- Looks good, thanks! r+ with some nits. ::: mozlog/mozlog/logger.py @@ +83,3 @@ > params['action'] = action > > + # The message be None. This is expected, and shouldn't cause nit: s/be/can be (?) @@ +102,5 @@ > + if hasattr(record, 'params'): > + # This message was created by a call to log_structured, > + # anything specified by the caller's params should act > + # as an override. > + output.update(getattr(record, 'params')) nit: can remove the if statement and use getattr(record, 'params', {}), or else just use record.params instead of getattr. @@ +107,5 @@ > + > + if record.msg and output.get('_message') is None: > + # For compatibility with callers using the printf like > + # API exposed by python logging, call the default formatter. > + output['_message'] = Formatter.format(Formatter(), record) nit: I believe we can just pass self instead of instantiating a new Formatter. @@ +111,5 @@ > + output['_message'] = Formatter.format(Formatter(), record) > + > + if output.get('indent') is not None: > + return json.dumps(output, indent=output['indent']) > + return json.dumps(output) nit: replace these three lines with "return json.dumps(output, indent=output.get('indent'))"
Attachment #786080 -
Flags: review?(ahalberstadt) → review+
Assignee | ||
Comment 2•11 years ago
|
||
https://github.com/mozilla/mozbase/commit/3c303e7ef1e04414f3a864495d33ffee0349d82e
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Updated•11 years ago
|
Blocks: structured-logging
Assignee | ||
Updated•11 years ago
|
No longer blocks: structured-logging
Assignee | ||
Updated•11 years ago
|
Blocks: structured-logging
You need to log in
before you can comment on or make changes to this bug.
Description
•