[Python-Dev] Proposed change to logging.basicConfig

Vinay Sajip vinay_sajip at yahoo.co.uk
Tue Mar 29 23:09:25 CEST 2011


Antoine Pitrou <solipsis <at> pitrou.net> writes:

> I'm not a logging expert, but the fact that your description above
> mentions at least two instances of special-casing make it sound like
> the API has an usability (or learnability) problem.

Well, basicConfig() was provided to make it as easy as possible to configure
logging for the common use cases - logging to console and logging to file. To do
this, keyword parameters are passed: stream= (defaulting to sys.stderr, for
logging to console) or filename= and filemode= which specify a file to log to.
These sets are not compatible. Of course I could have provided two different
functions with different signatures, but it seemed simpler to have a single
function, which is typically used in just one place in an application script.
This is unlike the cmp/key case Terry mentions, and in any case the effect of
passing incompatible parameters is documented in the case of basicConfig().

If by special casing you're referring to "(if it doesn't already have any
handlers)", that's existing behaviour, and not a change. If you're referring to
"the arguments will be ignored" sentence - Terry makes a valid point about
raising an exception if incompatible parameters are passed, and I will do this.
If you're referring to the sentence about formatters, I don't see it as a
special case, it's about convenience. Each logging handler can have a formatter,
and the proposed API allows both bespoke formatters to be set for individual
handlers and for a common formatter to be set for multiple handlers, with ISTM
minimal effort for the API user.

If you're referring to something else entirely, I'm not sure what that might be.

Regards,

Vinay Sajip




More information about the Python-Dev mailing list