Skip to content
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

[MRG] MNT Replaces stream handler with null handler #15386

Closed

Conversation

thomasjpfan
Copy link
Member

Reference Issues/PRs

Fixes #15122

What does this implement/fix? Explain your changes.

For reference: #9240 (comment)

Adding NullHandler based on https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

I don't get why we need to modify the logging handlers at all. Please explain

@@ -21,8 +21,7 @@
from ._config import get_config, set_config, config_context

logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)
logger.addHandler(logging.NullHandler())
Copy link
Member

Choose a reason for hiding this comment

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

Why not remove the logger.addHandler line altogether and leave it to default handler?

Copy link
Member Author

Choose a reason for hiding this comment

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

It has to do with the behavior of WARNING:

If the using application does not use logging, and library code makes logging calls, then (as described in the previous section) events of severity WARNING and greater will be printed to sys.stderr. This is regarded as the best default behaviour.

Anyways I am okay with removing the handler as well.

@thomasjpfan
Copy link
Member Author

My understanding that it is "best practice" to add the null handler to avoid "No handler found" warnings:

https://github.com/psf/requests/blob/d2590ee46c0641958b6d4792a206bd5171cb247d/requests/__init__.py#L124-L128

I am having seconds thoughts with setting up a logger in the first place. Without a user configuring a logging handler, the info logging events from datasets will not be shown.

@rth
Copy link
Member

rth commented Oct 30, 2019

I am having seconds thoughts with setting up a logger in the first place

Yeah, that's what I meant. Until we have a clean way for users to define a logger and use it in various estimators #78, I don't really understand why the current setup is necessary (as users are still not able to use logging with scikit-learn until I am missing something)?

@thomasjpfan
Copy link
Member Author

Logging is only used in sklearn.datasets. Want to move those to using print?

@rth
Copy link
Member

rth commented Oct 30, 2019

Logging is only used in sklearn.datasets. Want to move those to using print?

After reading in more detail the documentation about logging in libraries you link above maybe not. Will comment in more detail in the parent issue.

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.

Please don't configure logging in the top-level __init__.py
3 participants