-
Notifications
You must be signed in to change notification settings - Fork 51
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
use NullHandler for logging by default #150
Conversation
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.
This looks good to me, and seems functionally the same. My only concern would be memory issues (e.g., adafruit_logging
takes up precious RAM needed by a board). It may be worth seeing if this works on an M0 board. @brentru, was that a concern you had when making the library?
That's interesting and I have not considered that. Is there perhaps some tooling that would help with memory analysis ? |
Can you expand a bit on why the way it's done today with the None check is not a good idea? I don't know what you meant by handler juggling. This does seem to me like it would be functionally the same, but at the "cost" of extra RAM and the additional dependency needing to be loaded. I don't quite understand why having the NullHandler pre-set by default like this preferable to having it be None and using the if statements to determine whether it should try to log or not. I don't think I have an M0 device that I could hook up with airlift so I can't test that. Honestly though I would'nt be too surprised if it was already tough to get networking and minimqtt both imported and working even without expanding the RAM needed here. It's pretty tight already and the networking libraries are on the bigger side I think |
It's a readability issue and I'd hope that the code changes make it apparent. Currently in the code there are 32 checks that determine whether As for the handler juggling, it was alternative idea when I considered the possibilities of addressing the readability issue. Basically have a single logger with NullHandler and replace it with handlers from the logger passed to Another possibility would be to wrap this inside a function. |
I agree that makes for a mess.
That seems like the simplest solution that doesn't import a logging package when it isn't needed. Another idea would be to create an |
use fake logger instead
a72259c
to
6d8b72a
Compare
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 think this is good as well. It's then probably worth adding a docstring to the |
Not merged yet so could be added in this PR. |
@vladak is that something you mind doing? Basically, for the def __init___(self) -> None:
self.logger = NullLogger()
"""An optional logging attribute that can be set with with a Logger to enable debug logging.""" Feel free to change the description above, just an idea to communicate how. |
No issue other than my sleep schedule :-) |
also document the self.logger
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.
Thanks!
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADT7410 to 1.3.10 from 1.3.9: > Merge pull request adafruit/Adafruit_CircuitPython_ADT7410#23 from matsujirushi/patch-1 > Add upload url to release action > Add .venv to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.2.2 from 7.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#150 from vladak/logging_null_handler Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
This change makes sure the
self.logger
is always set to something. Given thatenable_logger()
has the flexibility of specifying the logging package, the loggers are switched, as opposed to handler juggling which might not be a good idea anyway as multiple log packages can be used simultaneously.