You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please don't configure logging in the top-level __init__.py #15122
In practice, this caused a hard-to-diagnose bug in our IPython- and sklearn-using application (actually, in more than one such application):
At application start time, we start an IPython kernel. That kernel swaps out sys.stdout and sys.stderr for its own custom streams, which rely on a lot of fairly complicated machinery (extra threads, ZMQ streams, the asyncio event loop, etc.)
sklearn was imported while that IPython kernel was running.
The log handler created at import time then picked up IPython's custom sys.stderr stream instead of the usual one.
At application stop time, the IPython kernel and associated machinery were stopped.
At process exit time, the stream associated to the handler was flushed (by the logging module's shutdown function, which is registered as an atexit handler). Because the IPython machinery was no longer active, we got a hard-to-understand traceback.
If the intent of the handler is to suppress the "No logger configured ..." messages from the std. lib., perhaps a logging.NullHandler could be used for that purpose instead? I'm happy to create a PR for this if the proposed change sounds acceptable.
If I understand the problem correctly we would like to use logging but that means that messages below the level of WARNING (i.e. INFO and DEBUG) will be hidden from the user unless they manually set the logging level. For instance, to give an example of library with logging see matplotlib documentation.
That is very different from the current scikit-learn API where estimators have a verbosity parameter. Also sklearn.datasets do use logging, with a custom log handler, hence this issue.
My question is if we use the standard logger and don't manually set/unset logging level how can we make verbosity parameter work as before?
We don't need the verbose parameter to work as before, as long as all
instances of the same class should share the same verbosity... we would
just define a logger name for each verbose estimator that matches the
public import path of the class.
Does than mean deprecating the verbose parameter altogether?
Or alternatively setting verbose parameter would then set the logging level for the logger from its module? There is then a question of what happens for the inter-module logging. Say TSNE(verbose=1) uses neighbors module for a large part of the runtime. You could just pass verbose parameter there, but then does that mean that the log level of sklearn.neighbors changed (e.g. if we call KNeighgborsClassifier from somewhere else)? unless we then reset the logging level each time an estimator is called..
Overall logging is nice application level; library level it sounds complicated.
Another data point, is that joblib is using logging for inter-process logging, but progress messages from the verbose parameter are still printed directly to stdout/stderr as far as I can tell.
Activity
mdickinson commentedon Oct 3, 2019
See #9240 for discussion leading to the introduction of this log configuration.
jnothman commentedon Oct 3, 2019
rth commentedon Oct 30, 2019
I think using logging overall makes sense, and https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library is an interesting read.
If I understand the problem correctly we would like to use logging but that means that messages below the level of
WARNING(i.e.INFOandDEBUG) will be hidden from the user unless they manually set the logging level. For instance, to give an example of library with logging seematplotlibdocumentation.That is very different from the current scikit-learn API where estimators have a
verbosityparameter. Alsosklearn.datasetsdo use logging, with a custom log handler, hence this issue.My question is if we use the standard logger and don't manually set/unset logging level how can we make
verbosityparameter work as before?jnothman commentedon Oct 30, 2019
rth commentedon Oct 30, 2019
Does than mean deprecating the
verboseparameter altogether?Or alternatively setting
verboseparameter would then set the logging level for the logger from its module? There is then a question of what happens for the inter-module logging. Say TSNE(verbose=1) usesneighborsmodule for a large part of the runtime. You could just passverboseparameter there, but then does that mean that the log level ofsklearn.neighborschanged (e.g. if we callKNeighgborsClassifierfrom somewhere else)? unless we then reset the logging level each time an estimator is called..Overall logging is nice application level; library level it sounds complicated.
rth commentedon Oct 30, 2019
Another data point, is that joblib is using logging for inter-process logging, but progress messages from the
verboseparameter are still printed directly to stdout/stderr as far as I can tell.jnothman commentedon Apr 27, 2020
I think we should avoid neglecting this for more releases. This bad-citizen code was inserted accidentally.
thomasjpfan commentedon May 4, 2020
Resolved by #16451