def scattering_logger(name):
levels = ["NUMERICS", "SCATTER"]
methods = [_log_for_numerics, _log_for_scatter]
for i, level in enumerate(levels):
level_name = level
level_value = globals()[level]
method_name = level_name.lower()
if hasattr(logging, level_name):
# print('{} already defined in logging module'.format(level_name))
continue
if hasattr(logging, method_name):
# print('{} already defined in logging module'.format(method_name))
continue
if hasattr(logging.getLoggerClass(), method_name):
# print('{} already defined in logger class'.format(method_name))
continue
logging.addLevelName(level_value, level_name)
setattr(logging, level_name, level_value)
setattr(logging.getLoggerClass(), method_name, methods[i])
# setattr(logging, method_name, _log_to_root)
logger = logging.getLogger(name)
if not logger.hasHandlers():
formatter = logging.Formatter(fmt="%(levelname)s (%(name)s): %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
# logger.handlers.clear()
logger.propagate = False
return logger