473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

parameters to logging.debug()

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
2 2336
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jjesso | last post by:
I am trying to add a new logging level. logging.config.fileConfig("bengineLog.cfg") logging.CLIENT = logging.INFO + 1 logging.addLevelName( logging.CLIENT, 'CLIENT' ) logging.root.setLevel( )...
3
by: Chris Smith | last post by:
Hola, pythonisas: The documentation for the logging module is good, but a bit obscure. In particular, there seems to be a lot of action at a distance. The fact that getLogger() can actually be a...
6
by: rh0dium | last post by:
Hi Experts!! I am trying to get the following little snippet to push my data to the function func(). What I would expect to happen is it to print out the contents of a and loglevel. But it's...
3
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.