Logging vs printing

Leo Breebaart leo at lspace.org
Mon May 8 14:11:36 CEST 2006


"alisonken1" <alisonken1 at gmail.com> writes:

> Leo Breebaart wrote:
>
> > I am writing fairly large console scripts in Python. They
> > have quite a few command-line options, which lead to
> > configuration variables that are needed all over the program
> > (e.g. the "--verbose" option alone is used by just about
> > every function and method).
> 
> <SNIP>
> 
> One question I have is about the "--verbose" option.
> 
> If you're doing something that is equivalent to logging to
> <file | console>, rather than continuing to pass the
> '--verbose' flag around, why not just use the built-in logging
> facility to manage the extra output?

Good point. It's not a real conscious decision, and I have one or
two other projects lying around where I do in fact use logging. I
think the main reason why I am not using it by default is
because, when all is said and done, it still comes easier to me
to resort to guarded print statements then to set up and use the
logging machinery.

This may well be a false economy in the long run, but it is
nevertheless how I perceive it in day-to-day programming. 

(Related to this is that while I found e.g. the optparse
documentation very clear and relevant to my needs, the logging
documentation and examples, while readable, just never seem to
relate to what I actually need. This is not a complaint -- just
a subjective observation.)

But you are right. Especially for the larger projects I really
should bite the bullet and start using the logging module.

-- 
Leo Breebaart  <leo at lspace.org>



More information about the Python-list mailing list