Closed Bug 1534341 Opened 5 years ago Closed 5 years ago

[mozlog] Allow passing messages down to formatters

Categories

(Testing :: Mozbase, enhancement, P3)

Version 3
enhancement

Tracking

(firefox68 fixed)

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: jgraham, Assigned: nikkis)

Details

Attachments

(1 file)

mozlog has a message passing system that can be used to configure handlers by calling send_message [1]. If the handler has a handle_message function registred for that kind of message then it will processs the message. This allows configuring handlers without having to know which handlers are actually present since the client code can just send whatever configuration messages it likes without worrying about whether anyone would recieve them.

Some handlers support a formatter that generates log messages and it would be good to configure those at runtime as well using a similar system. So the user would be able to dos something like mozlog.send_message("grouping_formatter", "show_logs", True) to set some configuration on that formatter if it happens to be in use.

I think the implementation here is just to update the StreamHandler and any other handler that has a formatter property to forward any messages they recieve down to the formatter after they have handled them.

[1] https://searchfox.org/mozilla-central/source/testing/mozbase/mozlog/mozlog/structuredlog.py#196

StreamHandler inherits from BaseHandler, which has a similar method to send_message in handle_message, already allowing topic, command and args to be set. It has the additional attribute of formatter. In the case there is a formatter, do want the result of handle_message (i.e. rv), passed through self.formatter before being returned?
I hope I'm understanding this correctly!
Thanks!

Yes, that sounds exactly correct.

Priority: -- → P3

This addition allows formatters to be configured by sending a message.

For example, the show_logs attribute has been added to the GroupingFormatter
to allow switching on/off the display of all log messages at runtime.
A generic handle_message method was added to the BaseFormatter to allow
attributes to be configured, with optional arguments for those that require
it.

An additional log(data) method has been implemented on the GroupingFormatter
that checks self.show_logs, and if True, displays all messages regardless of
failure or success, with component, level and stack.

A test may be required to ensure this is behaving as expected.

Pushed by james@hoppipolla.co.uk:
https://hg.mozilla.org/integration/autoland/rev/c05f29dd14f5
[mozlog] Allow passing messages down to formatters r=jgraham
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Assignee: nobody → nikkisharpley
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: