aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/utils
diff options
context:
space:
mode:
Diffstat (limited to 'fg21sim/utils')
-rw-r--r--fg21sim/utils/logging.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/fg21sim/utils/logging.py b/fg21sim/utils/logging.py
index 0abf4d3..2630a58 100644
--- a/fg21sim/utils/logging.py
+++ b/fg21sim/utils/logging.py
@@ -19,6 +19,7 @@ def setup_logging(dict_config=None, level=None, stream=None, logfile=None):
----------
dict_config : dict
Dict of logging configurations specified in the config file.
+ If this parameter specified, the logging will be reconfigured.
level : string;
Override the existing log level
stream : string; "stderr", "stdout", or ""
@@ -37,16 +38,22 @@ def setup_logging(dict_config=None, level=None, stream=None, logfile=None):
"""
# default file open mode for logging to file
filemode = "a"
+ root_logger = logging.getLogger()
#
if dict_config:
# XXX:
# "basicConfig()" does NOT accept paramter "filemode" if the
# corresponding parameter "filename" NOT specified.
filemode = dict_config.pop("filemode", filemode)
+ # Clear existing handlers, otherwise further "basicConfig" calls
+ # will be ignored
+ for handler in root_logger.handlers:
+ root_logger.removeHandler(handler)
+ # Initialize/reconfigure the logging, which will automatically
+ # create a ``Formatter`` for handlers if necessary, and adding
+ # the handlers to the "root" logger.
logging.basicConfig(**dict_config)
#
- root_logger = logging.getLogger()
- #
if level is not None:
level_int = getattr(logging, level.upper(), None)
if not isinstance(level_int, int):