From 6346a9e5f87073d0d80c63f53c1823e2f42edf4b Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 12 Nov 2008 12:51:54 +0000 Subject: [PATCH] utils.SetupLogging: Remove previously setup handlers If a logging function is called before the logging module is setup using utils.SetupLogging, it calls logging.basicConfig, which adds a StreamHandler, on its own. If we leave it in, all log output will be printed twice on stderr. This patch makes sure to remove all handlers before adding our own. Reviewed-by: iustinp --- lib/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/utils.py b/lib/utils.py index 47fe4cc22..7884366d5 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1558,6 +1558,10 @@ def SetupLogging(logfile, debug=False, stderr_logging=False, program=""): root_logger = logging.getLogger("") root_logger.setLevel(logging.NOTSET) + # Remove all previously setup handlers + for handler in root_logger.handlers: + root_logger.removeHandler(handler) + if stderr_logging: stderr_handler = logging.StreamHandler() stderr_handler.setFormatter(formatter) -- GitLab