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

Stefan Behnel behnel_ml at dvs1.informatik.tu-darmstadt.de
Wed Oct 20 16:43:47 CEST 2004

Paul Clinch schrieb:
> logging.fatal( 'Test is %(test)s' % values)
> is fine. An why shouldn't you use it in this fashion?

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?

Ok, I know there's an overhead anyway: function calls, object creation, 
etc. But copying strings and creating string representations of objects 
can be /very/ expensive and should only be done if the log message is 
definitely written.

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.


More information about the Python-list mailing list