From 0d4169a01e0a1d8bf0ca84fadea383cba14be150 Mon Sep 17 00:00:00 2001 From: Caitao Zhan Date: Wed, 20 Nov 2024 12:45:50 -0600 Subject: [PATCH] [minor] remove existing handlers in logging --- sequence/utils/log.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sequence/utils/log.py b/sequence/utils/log.py index 04ef5e4f..33d9f272 100644 --- a/sequence/utils/log.py +++ b/sequence/utils/log.py @@ -20,7 +20,7 @@ def _init_logger(): return lg -logger = _init_logger() +logger = _init_logger() # global logger # LOG_FORMAT = '{asctime} {simtime:<20,} {levelname:7} {module:20} {message}' LOG_FORMAT = '{simtime:<20,} {levelname:7} {module:20} {message}' # no asctime _log_modules = [] @@ -40,6 +40,10 @@ def set_logger(name: str, timeline, logfile="out.log"): global logger logger = logging.getLogger(name) + # remove existing handleers + for h in logger.handlers: + logger.removeHandler(h) + handler = logging.FileHandler(logfile) fmt = logging.Formatter(LOG_FORMAT, style='{') f = ContextFilter(timeline)