Logging: how to suppress default output when adding handlers?

Chris Shenton chris at shenton.org
Tue Jun 5 15:38:31 EDT 2007


Vinay Sajip <vinay_sajip at yahoo.co.uk> writes:

> The default handler is created because you are calling the convenience
> functions of the logging package: logging.error, etc. If you don't
> want the default handler to be created, either
>
> (a) Configure the logging system yourself before any logging call is
> made (I'm not sure why you're not doing this - it could be done in
> your main script before anything else happens) - or

Yeah, I think this is the cause.  Unfortunately I'm using a couple
dozen files and a bunch more libraries and if they're doing a
logging.debug() or whatnot they're creating this.  

Do you have any ideas how I can trace where the first call is made?
This seems a newbie question but if I have a bunch of other files
which do stuff like "from sqlalchemy import *" they might be invoking
a logging call so I'm not sure how to chase these down.

> (b) Make calls on a specific named logger, e.g.
> logging.getLogger("logtest2").error("foo"), rather than
> logging.error("foo") which is for casual/unsophisticated use only.

I'm dreading having to be so verbose with my (copious) loggers, which
is why I was curious if there was a way to nuke any auto-created
ones.  I thought calling logging.shutdown() before configuring my
loggers might do this but it didn't.  

Thanks.



More information about the Python-list mailing list