Skip to content

log

plantimager.log Link

configure_logger Link

configure_logger(name, log_path='', log_level='INFO')

Return a configured logger.

Parameters:

Name Type Description Default
name str

The name of the logger.

required
log_path str

A file path to save the log. Defaults to ''.

''
log_level (CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET)

A valid logging level. Defaults to 'INFO'.

'CRITICAL'
Source code in plantimager/log.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def configure_logger(name, log_path="", log_level='INFO'):
    """Return a configured logger.

    Parameters
    ----------
    name : str
        The name of the logger.
    log_path : str
        A file path to save the log.
        Defaults to `''`.
    log_level : {'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'}
        A valid logging level.
        Defaults to `'INFO'`.
    """
    colored_formatter = ColoredFormatter(
        "%(log_color)s%(levelname)-8s%(reset)s %(bg_blue)s[%(name)s]%(reset)s %(message)s",
        datefmt=None,
        reset=True,
        style='%',
    )
    simple_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(lineno)d: %(message)s")

    # create console handler:
    console = logging.StreamHandler()
    console.setFormatter(colored_formatter)

    logger = logging.getLogger(name)
    logger.addHandler(console)
    logger.setLevel(getattr(logging, log_level))

    if log_path is not None and log_path != "":
        # create file handler:
        fh = logging.FileHandler(Path(log_path) / f'{name}.log', mode='w')
        fh.setFormatter(simple_formatter)
        logger.addHandler(fh)

    return logger

get_logging_config Link

get_logging_config(name='root', log_level='INFO')

Return the logging configuration.

Parameters:

Name Type Description Default
name str

The name of the logger. Defaults to 'root'.

'root'
log_level (CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET)

A valid logging level. Defaults to 'INFO'.

'CRITICAL'
Source code in plantimager/log.py
61
62
63
64
65
66
67
68
69
70
71
72
73
def get_logging_config(name='root', log_level='INFO'):
    """Return the logging configuration.

    Parameters
    ----------
    name : str
        The name of the logger.
        Defaults to `'root'`.
    log_level : {'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'}
        A valid logging level.
        Defaults to `'INFO'`.
    """
    return LOGGING_CFG.format(name, log_level)