Remove root handler from logger
Florian Lindner
mailinglists at xgm.de
Mon May 14 05:15:57 EDT 2012
Hello,
I configure my logging on application startup like that:
logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(FORMAT))
logging.getLogger().addHandler(ch)
In one module of my application I want a logger that does not log to logfile
but to another file. How can I get a logger that is either plain (no handlers
attached) or remove a handler?
The handlers that are derived from the root logger are not shown in handlers:
(Pdb) logger1.handlers
[]
(Pdb) logging.getLogger().handlers
[<logging.FileHandler object at 0x7f3e8f6f0e90>, <logging.StreamHandler object
at 0x7f3e8f731450>]
How can I remove the FileHandler and StreamHandler from logger1 without
affecting the root logger?
logger1.removeHandler() does not work since there are no handlers on logger1.
Thanks,
Florian
More information about the Python-list
mailing list