[Python-Dev] Using logging in the stdlib and its unit tests (original) (raw)

skip at pobox.com skip at pobox.com
Wed Dec 8 20:14:25 CET 2010


>> On a slightly tangential note, what do you think of the idea of
>> library code including info or debug level logging? In effect,
>> tracing and diagnostic code built in and available simply by changing
>> the logging level?

Vinay> That's how it works right now. You get info() and debug()
Vinay> messages sent via calls in library code, just by changing the
Vinay> level of (say) the root logger.

There can be performance implications if you log heavily. I don't know how the code is organized, but functionally these two calls are equivalent:

>>> logging.error("error 1 2 3 %s" % "yup")
ERROR:root:error 1 2 3 yup
>>> logging.error("error 1 2 3 %s", "yup")
ERROR:root:error 1 2 3 yup

The second form should be preferred in library code as long as the format string expansion is deferred until after the test is made to emit the message.

Skip



More information about the Python-Dev mailing list