Skip to content

Log

NUMERICS = 15 module-attribute

SCATTER = 25 module-attribute

scattering_logger

Source code in yasfpy/log.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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

Comments