-
Notifications
You must be signed in to change notification settings - Fork 14
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 minimal fixes to get logging working #184
base: main
Are you sure you want to change the base?
Conversation
There was previously no central initializing of handlers for logging, so only WARNING and higher was getting logged and without a modicum of formatting. Add a centralized _logging module to initialize the base logger. This gets called at the two app entrypoints: snakebids.admin:main and upon initialization of SnakebidsApp
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 for making this PR, I think this is worth implementing and was a good motivation to read about Python logging more specifically.
This all seems pretty much in line with the best practices, but there are a couple of changes that would line up better with my gut preference (I'm open to reasons that the current way is preferable, though):
- Set up the top-level logger in
__init__.py
(withlogging.getLogger(__name__)
) to make its existence explicit to anyone who looks there. - Don't set up a formatter for the top-level logger when
SnakeBidsApp
is instantiated (best practice seems to be to leave the default config in place in a library and let the caller add formatters etc. if they want). - Set up the formatter for the admin CLI in
admin.py
and remove_logging
(as of now I don't think there are any plans to add another module that would need_logging.setup_logger
). - Add an example of logger setup (could be the same as what's in
_logging
now) in the templaterun.py
so people can see how to edit the config in their generated apps if they want.
I'm not familiar enough with the details of python importing: would that code be rerun every single time
I am aware of this, although for clarity, I believe the issue lies more with adding a handler, rather than just the formatting of the handler. I should have explained my rationale better here, but I forgot. The idea was that since snakebids is sort of supposed to be batteries-included, and since setting up logging is probably not at the forefront a snakebids devs mind, I wanted to have something working out of the box. This is why I made the snakebids root logger available as a property of Even given the above rationalization, a simpler means to disable this built-in logging could be provided (something very doable, but we could add simple method or something)
Response to these follows from above. |
The key thing here I think is that "Multiple calls to getLogger() with the same name will always return a reference to the same Logger object." So whether
I guess the fundamental question here is what the easiest way is for app developers to edit the logging config. |
I've definitely seen this type of thing in libraries before (just documenting the name of the logger), but I can't remember where. The reason I had a property had more to do with timing... With refactoring the property can disappear. One other thing that occurs to me, and that the PR in it's current state doesn't achieve, is that if just But I think this drives at my basic point and concern: in the absence of any special actions, snakebids needs to be able to print out its logs. For anything less severe than warning, this means adding a handler somewhere.
But would this not clutter up the |
Ah I guess my thinking here was that our desired default behaviour is just to print warnings, errors, and any non-log output via That said I think (without much thought about its practicality) adding default CLI args for increased/decreased verbosity would be a reasonable approach (i.e.
I think it's largely fine to just print out errors and warnings here, but agree that it would be hard for beginners to know how to get more fine-grained logs in this situation. If we anticipate a lot of beginners using |
Searching the current repository for
This gets into the very heart of complications involved in wrapping another app. Snakemake obviously has its own logging and cli switches, including a somewhat complicated keyword version of |
I did not write this clearly -- I meant that important runtime (i.e. non-log) outputs should be be output with
Agreed on this and the rest of what you said in this paragraph about settling on a consistent log level approach. I think in particular all the info-level logs I found in the repo currently could justifiably be warnings.
This all makes sense to me! Having two verbosity handling mechanisms side by side and clearly delineating them would certainly introduce another instance of this class of problem. |
Okay, then for this PR, there were a few issues and inconsistencies that need to be dealt with, but I'll remove the handlers and marking everything that should be logged as at least warning. That'll get everything to a "better-than-nothing" functional state, which was the original intent of this PR. |
I will continue to keep the handler for the administrative tasks, however. |
There was previously no central initializing of handlers for logging, so only WARNING and higher was getting logged and without a modicum of formatting.
This adds a centralized _logging module to initialize the base logger. This gets called at the two app entrypoints: snakebids.admin:main and upon initialization of SnakebidsApp
I've never implemented logging before, so I wasn't sure of the "correct" way to do it; if anyone has suggestions, let me know. Obviously the system could get more sophisticated, especially with colors, etc, but this gets the basics working.