From 368b7d10a7058d920ce3feaa231c9fc0760eec4b Mon Sep 17 00:00:00 2001 From: Yifan Yang <64255737+yfyeung@users.noreply.github.com> Date: Wed, 24 Apr 2024 14:31:25 +0800 Subject: [PATCH] clear log handlers before setup (#1603) --- icefall/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/icefall/utils.py b/icefall/utils.py index 2cb2edf93a..ec6aee6d0b 100644 --- a/icefall/utils.py +++ b/icefall/utils.py @@ -110,6 +110,13 @@ def str2bool(v): raise argparse.ArgumentTypeError("Boolean value expected.") +def clear_log_handlers(): + logger = logging.getLogger() + handlers = logger.handlers[:] + for handler in handlers: + logger.removeHandler(handler) + + def setup_logger( log_filename: Pathlike, log_level: str = "info", @@ -126,6 +133,8 @@ def setup_logger( use_console: True to also print logs to console. """ + clear_log_handlers() + now = datetime.now() date_time = now.strftime("%Y-%m-%d-%H-%M-%S") if dist.is_available() and dist.is_initialized():