Skip to content

Null Logger #18

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

Merged
merged 3 commits into from
Mar 17, 2021
Merged

Null Logger #18

merged 3 commits into from
Mar 17, 2021

Conversation

dastels
Copy link
Collaborator

@dastels dastels commented Mar 4, 2021

This implements the "Null Object" pattern. It allows logging to be completely and efficiently disabled without having to sprinkle "if logger" guards on every logger call (which can be error prone during maintenance).

dastels added 3 commits March 4, 2021 15:32
This implements the "Null Object" pattern. It allows logging to be completely and efficiently disabled without having to sprinkle "if logger" guards on every logger call (which can be error prone during maintenance).
@brentru
Copy link
Member

brentru commented Mar 4, 2021

@dastels Is this compatible with the CPython logging API as well?

@dastels
Copy link
Collaborator Author

dastels commented Mar 4, 2021

Brent: unknown. There isn't the impetus to completely null it out in cpython as there is in CircuitPython. The motivation was seeing many if self.logger: guards in the minimqtt code. One of which led to a bug where it was if self.logger and ..., then an else clause was added that pertained to the second condition which got executed with a None self.logger. Having a Null logger is a better design approach. All that has to change is assignment of the logger... the client code can happily go about logging without caring.

Cpython's getLogger with a None argument returns the root of the logger hierarchy, which is something the CircuitPython logger doesn't support anyway. One could consider the Null Logger to be the de facto root. I added support for an empty string to make specifying it a bit more convenient where the name is coming from somewhere stringy (maybe a JSON config).

Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thanks for clarifying @dastels

@brentru brentru merged commit d61dc59 into adafruit:master Mar 17, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 20, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 3.5.7 from 3.5.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#128 from adafruit/anecdata-patch-2
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#126 from adafruit/anecdata-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_LTR390 to 1.1.0 from 1.0.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_LTR390#3 from CedarGroveStudios/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font to 1.3.7 from 1.3.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#41 from jepler/use-bitmaptools-readinto

Updating https://github.com/adafruit/Adafruit_CircuitPython_datetime to 1.1.2 from 1.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_datetime#7 from brentru/fix-failing-tests
  > Merge pull request adafruit/Adafruit_CircuitPython_datetime#6 from cognitivegears/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 0.14.0 from 0.13.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#45 from kmatch98/master
  > "Increase duplicate code check threshold "
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#46 from adafruit/tests-linting

Updating https://github.com/adafruit/Adafruit_CircuitPython_Logging to 1.2.8 from 1.2.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_Logging#18 from dastels/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.3.0 from 3.2.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_Motor#54 from CedarGroveStudios/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants