-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] Use logging.info instead of print (#6929) #6930
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
Conversation
Are there instances that need to be fixed elsewhere in |
print('Cache loading failed') | ||
print(80 * '_') | ||
print(e) | ||
logging.info(80 * '_') |
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 would be better composed as a single multiline string.
from a cursory glance at a github search for |
There are a lot of instances outside of datasets so I'll start hunting those print statements as well |
I think you're not wrong, @nelson-liu, but cursory doesn't tell you a lot without eliminating
|
very true @jnothman , good catch / sorry for any confusion. |
I am really not positive about using the logging module. It has a default behavior that is not at all what users may want, and changing that requires expertise. The way we usually do it is by having an if verbose > 0: print(msg) |
In these sorts of cases I'd be okay with |
How about we add a logger that by default prints to STDOUT? That should be fairly simple, right? |
Ordinarily you leave the logger config to the user. Do you suggest we On 14 October 2016 at 03:06, Andreas Mueller notifications@github.com
|
Some minimal config, yeah. |
This will complicate life for people using proper logging. |
@podshumok can you elaborate? How would it interfere with any existing logging you're doing? |
Basically if there is no handler, we could register a handler that prints to stdout, I guess? |
Python standard logging is pretty configurable. One can set different handlers for different levels for different loggers. Usually one don't want to use (log to a) logger ( But configuring other loggers is fine (One may want to suppress errors from one module/package and redirect all messages from another one with maximum verbosity to a file and pipe all critical messages from everything else to a Sentry instance). By looking at Anyway doing logging at import is not very common or "welcomed" solution. If such thing is going to happen users should be warned about it and proper instructions on disabling this thing should be provided too. So, if any logging is going to be integrated in sklearn (which is a good thing), it is just a question of about what users should be warned: |
I would vote for b), but I still didn't see how this will complicate life for people already using logging. |
Bumping this PR. Having things logged by default is very useful in distributed settings. |
Having things logged by default is very useful in distributed settings.
I lost half an hour to get the logging module to print anything last week
(because of human errors on my side). I am not excited: unless work is
done for the usability, it will make things much harder for the common
cases.
|
But logging to stdout is not exactly good behaviour for a library. Perhaps
we should consider using a config setting to allow users to opt-in to
logging?
…On 8 June 2018 at 04:51, Gael Varoquaux ***@***.***> wrote:
> Having things logged by default is very useful in distributed settings.
I lost half an hour to get the logging module to print anything last week
(because of human errors on my side). I am not excited: unless work is
done for the usability, it will make things much harder for the common
cases.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6930 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz66DNMMt9F_PEkcfJNLNyChKCgNuSks5t6XZFgaJpZM4I8fTM>
.
|
But logging to stdout is not exactly good behaviour for a library. Perhaps
we should consider using a config setting to allow users to opt-in to
logging?
Granted. As long as it comes to no cost to usability. That requirement
involves a bit of work!
|
we can register our own logger and make it print to stdout by default, right? What's the issue with that? The main problem is creating a unique enough string for our logger name. But arguable no-one should have used sklearn as a logger name because it's the module name. |
I think it's hard to see all the backwards compatibility problems here, and
we'll probably break someone's expectations somewhere in non-critical ways.
I'd be in favour in the first instance of something like Andy suggests, or
at least replacing all uses of print by some sklearn.utils function
|
Do you know if there is a reason e.g. numpy, scipy or pandas never implemented logging? I would have though that could have been useful e.g. for scipy solvers. I couldn't find relevant discussions about it on their issue trackers but maybe I missed something. So is matplotlib then the only large scientific python library that uses logging at present ? Does anyone know what has been their feedback about it since matplotlib/matplotlib#9313 was merged? |
also see #78 |
#78 still doesn't have a consensus, and we'd need a new start for that. Closing this PR. |
Reference Issue
Fixes #6929
What does this implement/fix? Explain your changes.
Replaces 'print' with 'logging.info' so the library will no longer print to stdout.
Any other comments?