-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some 🟥🟧🟨🟩🟦🟪 to the logs #478
Conversation
if a.done: | ||
self._logger.debug( | ||
"Assertion '%s' finished after event %s", a.name, event_descr | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous assertion success/failure messages that included details of events that made the assertion succeed or fail were a bit unreadable, so I've decided to split them in two messages: one containing the event details and logged with DEBUG
level, and another one, in color, only stating that the assertion succeeds or fails with a given result, logged as before (usually as INFO
).
@@ -148,16 +155,25 @@ def configure_logging_for_test(test_log_dir: Path) -> None: | |||
api_monitor_logger.handlers.remove(proxy_handler) | |||
|
|||
|
|||
class MonitorHandler(logging.Handler): | |||
"""A logging handler that passes messages from log records to an event monitor.""" | |||
class MonitoringFilter(logging.Filter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched from using custom logging.Handler
to logging.Filter
. Filters are run before handlers for a record, so this ensures that the record is modified by the filter (by adding color) before passing it to any handler. Moreover, after reading logging
docs I think it's more idiomatic to modify the record in a filter than in a handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 🏳️🌈 I'd say we could use even more colours for some parts of our logs (e.g. making Running step ...
log lines less contrasting could increase the overall readability). That said, I think it could be a good topic for a separate PR.
class MonitoringFilter(logging.Filter): | ||
"""A logging `Filter` that feeds messages to the underlying event monitor. | ||
|
||
After doing this it also adds some color to the messages for greater fun. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👯
Let's output some logs in color:
🟦 output of a command run with
Probe.run_command_on_host()
🟩 assertion success messages
🟥 assertion failure messages
Colors are removed when logging to a file.