-
Notifications
You must be signed in to change notification settings - Fork 20
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
Null Logger #18
Conversation
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 Is this compatible with the CPython |
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). |
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.
Understood, thanks for clarifying @dastels
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
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).