Skip to content

Refactor logging setup to be more explicit and cleaner.#761

Merged
jb3 merged 2 commits into
masterfrom
logging
Feb 20, 2020
Merged

Refactor logging setup to be more explicit and cleaner.#761
jb3 merged 2 commits into
masterfrom
logging

Conversation

@scragly
Copy link
Copy Markdown
Contributor

@scragly scragly commented Feb 20, 2020

Description

This PR is to refactor the logging prep in our __init__.py module to avoid issues encountered with import sensitivity and overwritten logging settings.

It simplifies some existing code and removed anything that was no longer useful, such as the logmatic dependency and the aio_pika log setup..

The formatting of the logger was tweaked.

flake8-annotations have also been updated 2.0 and adjusted to use the ANN rule prefix.

Background

Logging Levels and Handlers

Previously, we had a for loop that indiscriminately forced all registered individual loggers to be a set level and to each have a set list of handlers.

This resulted in us being forced to never import a library/module that needs to have logging explicitly set a certain way before this for loop lest it be overwritten with the generic settings.

This results in unexpected and undesirable behaviours, such as if we need to patch discord.py before anything uses it, it'll be forced back into DEBUG level logging by the time we run the bot, outputting excessive discord api logs.

Logmatic

The logmatic dependency was used exclusively for it's JSONFormatter, which is not being used for anything and isn't more human readable than standard log output.

Flake8 Annotations

CI checks failed to install typed_ast when flake8-annotations was updated to v1.3:

flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "TYP" due to No module named 'typed_ast'.

Might as well update and adjust to the new major release due to this small inconvenience.

Changes

The logmatic dependency was removed, the pipfile relocked and the log handlers kept to just the stream handler and the standard file handler.

The for loop for dynamic forcing of all existing logs to use set levels and handlers was removed in favour of a clear and explicit setup of known loggers.

The aio_pika logger setup was removed as it's no longer a dependency in this project.

Formatting of the logs has been adjusted to:

  • Avoid wasting horizontal space by removing the buffer that was used for alignments.
  • Use the standard datetime format which uses YYYY-MM-DD (2020-02-20) for dates and added back in microseconds, rather than the previous MMM DD (Feb 20).

v2.0 of flake8-annotations was put into the pipfile and updated in the lock, and the tox.ini file was updated to use ANN prefix for the rules after the change from TYP in previous versions.

@scragly scragly requested a review from a team as a code owner February 20, 2020 13:00
@scragly scragly requested review from jb3 and jerbob and removed request for a team February 20, 2020 13:00
@scragly scragly added a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: dependencies Related to package dependencies and management p: 1 - high High Priority status: needs review t: bug Something isn't working labels Feb 20, 2020
@jb3 jb3 merged commit f5dcc12 into master Feb 20, 2020
@jb3 jb3 deleted the logging branch February 20, 2020 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: dependencies Related to package dependencies and management p: 1 - high High Priority t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants