[Python-Dev] Using logging in the stdlib and its unit tests

Nick Coghlan ncoghlan at gmail.com
Thu Dec 9 06:57:16 CET 2010

On Thu, Dec 9, 2010 at 4:49 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 8 December 2010 14:52, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> As I see it, there aren't many cases at the *library* level where
>> logging errors is more appropriate than raising exceptions:
> 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?

It's a trade-off between performance and the ability to diagnose
faults and what you want to do will vary by application and problem
domain. My background is in working on distributed projects where we
need enough diagnostic information to debug one-off failures of the
live system, so I'm in favour of the idea in general, but doing it
*can* carry a fairly hefty speed cost (you can ameliorate that to some
degree by handing off the actual I/O to a separate thread, but the
system would still be faster if the log messages weren't there).

As Skip says, you definitely want to take advantage of the lazy string
formatting when doing this with the Python logging module.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list