Closed Bug 901788 Opened 12 years ago Closed 12 years ago

Mozlog's json formatter should populate defaults for unstructured callers

Categories

(Testing :: Mozbase, defect)

defect
Not set
normal

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.
Attachment #786080 - Flags: review?(ahalberstadt)
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+
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: