By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,180 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,180 IT Pros & Developers. It's quick & easy.

parameters to logging.debug()

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Winston WOLFF wrote:
- If you like the current format, it is very easily done using the % operator with no loss of clarity.


But what about loss of performance? I don't want string formatting done
if the debugging output isn't even going to make it to the handler.
-Brian

Jul 18 '05 #2

P: n/a
Winston WOLFF wrote:
What do people think about changing the parameters to logging.debug() to
be more like the parameters to print?
I think it will break a lot of software that uses the current API.
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) )


That argument could also be made about your proposal. You can always type:

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

(Isn't Python going to start auto-stringizing the items in a join
sometime soon?)

Or better yet, you can subclass your own logger that does this
automatically. That's one of the reasons the logging stuff is so
extensible ;-)
--
Michael Hoffman
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.