-
Notifications
You must be signed in to change notification settings - Fork 73
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
Don't register a non-Null logging handler #232
Conversation
Per the Python docs [1]: "It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers." [1] https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library The best practice to only add "NullHandler" and to let _applications_ add their own handlers if desired.
💖 Thanks for opening your first pull request! 💖 Please make sure you read the following:
A few things to keep in mind:
|
This very well could have been copied from MetPy/Siphon. The behavior you mention for Python (where it logs to stderr by default) was new with 3.x. So in the days where everyone was support 2.7 and 3.x, adding the But yeah, not necessary these days thankfully. |
@shoyer thanks for submitting this! I agree that in most cases users of the library should set the handler. But this does get tricky when we blur the line between end users and developers. Pooch serves both library developers (who mainly use One issue I see with simply disabling the default handler is that it would kind of break our current behavior for dependent packages. I don't want to have them suddenly wondering why Pooch stopped printing download messages. We could implement this change and make a 2.0 release but I would want to give people warning for at least 1 release that this will be changed. A possible solution would be:
I don't know if this is recommended or even reasonable way to use cc @danshapero who implemented the logging code |
The reason I added the logging code in the first place was to make it possible to configure how much feedback Pooch would give you. Before, the code used I'm not really sure whether I think this behavior should be changed. It seems really unlikely that it would break someone's code or workflow, so it's maybe not of the same severity as changing the API. As a developer of a downstream application, I set the Pooch logging level to warning which mostly silences the text feedback. At the same time, most of the datasets I work with are > 1GB, so having a progress bar while downloading something is much more valuable feedback than a logging event after it's completed downloading. |
@danshapero thanks for the feedback 👍🏽 I've been thinking a bit more about this but I'm not very familiar with If we register a handler (say by calling If the answer is "no", then we could not set the default handler and move it inside a If it's "yes", then we'll have to think of a workaround. Having to import |
I've been doing some digging here and I'm thinking that the logging module is just not what we need for info output to users. Here is an example where our current implementation fails (remember that our default is verbosity ON):
import pooch
pooch.get_logger().setLevel("WARNING")
def fetch():
fname = pooch.retrieve(
url="doi:10.6084/m9.figshare.14763051.v1/tiny-data.txt",
known_hash="md5:70e2afd3fd7e336ae478b1e740a5f08e",
)
return fname
import package1
import pooch
def fetch():
fname = pooch.retrieve(
url="doi:10.6084/m9.figshare.14763051.v1/store.zip",
known_hash="md5:7008231125631739b64720d1526619ae",
)
return fname
import package2
import pooch
package2.fetch()
pooch.retrieve(
url="doi:10.5281/zenodo.4924875/store.zip",
known_hash="md5:7008231125631739b64720d1526619ae",
) In this case, there is no logging output for Requiring users to set handlers and make sure they don't interfere with other people's code seems a bit unreasonable when this could all be fixed by simply printing to STDERR and introducing a |
Per the Python docs [1]: "It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers."
[1] https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
Pooch is a library, so the best practice to only add "NullHandler" and to let applications add their own handlers if desired.
I imagine this change might have some implications for Pooch users, but I think it probably makes sense? On the other hand, I know the boundaries between "applications" and "libraries" can get blurry for libraries that are mostly run interactively...