parameters to logging.debug()

Winston WOLFF stuff2 at obNOSPAMPLEASEcore.com
Tue Oct 26 11:10:28 EDT 2004


What do people think about changing the parameters to logging.debug() 
to be more like the parameters to print?  As you know, you can pass 
multiple parameters to print, and they are all printed out with a space 
between each.  I find this more useful than the current method which 
just takes the first parameter and submits it to the % operator with 
the other parameters.  From a coding point of view, I find it to better 
to type this because all the strings are next to their labels:

	log.debug("index=",i, "dict=", dict, "x=", x, "y=", y, "z=", z)

compared to this because the labels are all at the beginning, and you 
have to spend some time keeping things in the right order:

	log.debug( "index=%i  dict=%s  x=%d y=%d z=%d", i, dict, x, y, z)

Also, for those who like the second format better, you can always type:
	log.debug( "index=%i  dict=%s  x=%d y=%d z=%d" % ( i, dict, x, y, z) )

I know it might be a little late to make such a drastic change to the 
logging API, but I really think it would be worthwhile.  Here are my 
reasons summarized again:

Why should we change the log.debug/info/warn/error() API:
	- It will match the print statement, which is what many people use already
	- It keeps the labels next to the variables you are printing.  This 
makes it easier to change which variables you are printing, as one does 
when debugging.
	- If you like the current format, it is very easily done using the % 
operator with no loss of clarity.
	- A list of parmeters that are just printed out after converting with 
repr() is less error prone than what we have now.  If you mess up the 
sequence of %i, %s, etc, then you might pass a string to your %i 
parameter but not notice until your debug message is actually called.

-Winston




More information about the Python-list mailing list