Logging messages with dictionary args in Python 2.4b1 leads to exception

Steve Holden steve at holdenweb.com
Thu Oct 21 19:36:34 EDT 2004


Vinay Sajip wrote:

>>I thought a logging API was usually trying to do costly things only when 
>>it knows it has to. You /could/ do that, but since it doesn't come for 
>>free - why not first do the check if you will actually log this message?
> 
> 
> Right.
>  
> 
>>I'd simply say that constructing a log message from arguments is such a 
>>common thing that it is worth providing efficient API support for it. And 
>>I think it's truely counter-pythonic to prevent the usage of dictionaries 
>>at this point.
> 
> 
> Patch checked into CVS. Now:
> 
> 
>>>>logging.warn('%(string)s and the %(number)d dwarves', {'string':
> 
> 'Snow White', 'number':7})
> 
> gives
> 
> WARNING:root:Snow White and the 7 dwarves
> 
> Regards,
> 
> 
> Vinay

But how much simpler

logging.want("%(string)s and the %(number)d dwarves",
                 string="Snow White", number=7)

seems (to me). Use kwargs!

regards
  Steve
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119



More information about the Python-list mailing list