secure loggers configuration to be configured only once
@@ -93,7 +93,6 @@ def setup_new_file_handler(logger_name, log_level, log_filename, formatter, filt
"""
logger = logging.getLogger(logger_name)
cfh = logging.FileHandler(log_filename, 'w')
- print("setup_new_file_handler(): logger FileHandler = {}, its stream = {}, id(stream) = {}".format(cfh, cfh.stream, id(cfh.stream)))
cfh.setLevel(log_level)
cfh.setFormatter(formatter)
if filter:
@@ -121,7 +120,8 @@ def _add_new_file_handler(logger_name,
if "{}->{}".format(logger_name, logfile_full_path) not in logger_list:
logger_list.append("{}->{}".format(logger_name, logfile_full_path))
else:
- return
+ # return
+ pass
_prepare_logs_folder(logfile_full_path)
setup_new_file_handler(logger_name=logger_name,
@@ -203,6 +203,7 @@ def create_logger(name,
def configure_moler_main_logger():
"""Configure main logger of Moler"""
# warning or above go to logfile
+ if 'moler' not in active_loggers:
print("inside configure_moler_main_logger()")
logger = create_logger(name='moler', log_level=TRACE, datefmt=date_format)
logger.propagate = True
@@ -230,7 +231,9 @@ def configure_moler_main_logger():
def configure_runner_logger(runner_name):
"""Configure logger with file storing runner's log"""
- create_logger(name='moler.runner.{}'.format(runner_name),
+ logger_name = 'moler.runner.{}'.format(runner_name)
+ if logger_name not in active_loggers:
+ create_logger(name=logger_name,
log_file='moler.runner.{}.log'.format(runner_name),
log_level=debug_level_or_info_level(),
log_format="%(asctime)s.%(msecs)03d %(levelname)-10s |%(message)s",
@@ -242,6 +245,7 @@ def configure_runner_logger(runner_name):
def configure_device_logger(connection_name, propagate=False):
"""Configure logger with file storing connection's log"""
logger_name = 'moler.{}'.format(connection_name)
+ if logger_name not in active_loggers:
logger = create_logger(name=logger_name, log_level=TRACE)
logger.propagate = propagate
conn_formatter = MultilineWithDirectionFormatter(fmt="%(asctime)s.%(msecs)03d %(transfer_direction)s|%(message)s",
@@ -257,7 +261,8 @@ def configure_device_logger(connection_name, propagate=False):
_add_raw_file_handler(logger_name=logger_name, log_file='{}.raw.log'.format(logger_name))
if debug_level == TRACE:
_add_raw_trace_file_handler(logger_name=logger_name, log_file='{}.raw.trace.log'.format(logger_name))
-
+ else:
+ logger = logging.getLogger(logger_name)
return logger
