Logging: how to suppress default output when adding handlers?
vinay_sajip at yahoo.co.uk
Tue Jun 5 16:36:25 CEST 2007
On Jun 5, 2:44 pm, Chris Shenton <c... at shenton.org> wrote:
> 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, thelogging
> system will create a default logger that *also* emits logs, which I
> can't seem to get rid of. Is there a way I can suppress the creation
> of this default logger, or remove it when I 'm setting up my handlers?
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
(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.
More information about the Python-list