[Python-Dev] Using logging in the stdlib and its unit tests (original) (raw)
Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Dec 8 02:19:45 CET 2010
- Previous message: [Python-Dev] Using logging in the stdlib and its unit tests
- Next message: [Python-Dev] Using logging in the stdlib and its unit tests
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Antoine Pitrou <solipsis pitrou.net> writes:
Why wouldn't it be the default for all logging calls ? Such special cases don't really make things easy to remember.
One size doesn't fit all. Everything's documented reasonably well. If you use it often, you remember it. If you use it seldom, you might need to look things up.
You seem pretty tied up to the "application developer" situation. There are cases (scripts, prototyping, etc.) where you certainly want to see error messages (errors should not pass silently) but don't want to configure logging for each of the libraries you use.
You don't have to configure each of the libraries you use. The "application developer" = "The developer who is not writing a library" = "The person writing a script, prototyping, etc." I don't mean Application with a capital A. I'm just using it as a convenient label to mean a library user who is not writing a library themselves.
Having convenient and understandable defaults would go a long way towards making logging more usable, IMO.
The defaults are I believe reasonably convenient, or at least not inconvenient:
If writing a library, add a NullHandler to the top-level logger of your library, don't add any other handlers by default (i.e. on import), document the names of the loggers you use. Otherwise, see the following.
If writing a simple script, prototyping etc. i.e. for casual use, use logging.debug(), logging.info() etc. That's easy enough and convenient enough for casual users to remember, I hope. All WARNING, ERROR and CRITICAL events in your code and in that of any libraries you use will be printed to sys.stderr.
If slightly less than very casual use (e.g. you want to log to file, or want a specific message format), call basicConfig(). Just the one extra line to remember to do, hopefully not too inconvenient. All WARNING, ERROR and CRITICAL events in your code and in that of any libraries you use will be printed to sys.stderr, unless you specify a file to log to and/or a different logging level, in which case what you specified will be used as destination/threshold for logging messages.
For more advanced use, use programmatic configuration, fileConfig or dictConfig to specify a configuration. Convenience is inversely proportional to how involved the configuration is.
If you can specify what you think is inconvenient in the above, that would be helpful.
Regards,
Vinay Sajip
- Previous message: [Python-Dev] Using logging in the stdlib and its unit tests
- Next message: [Python-Dev] Using logging in the stdlib and its unit tests
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]