Logging

YFPY module for configuring and formatting the custom logger.

get_logger

get_logger(name, level=INFO)

Get custom YFPY logger object.

Parameters:
  • name (str) –

    The module name for the logger.

  • level (int, default: INFO ) –

    The log level for the logger. Default level set to INFO.

Returns:
  • Logger( Logger ) –

    A Python Logger object with custom configuration and formatting.

Source code in yfpy/logger.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def get_logger(name: str, level: int = INFO) -> Logger:
    """Get custom YFPY logger object.

    Args:
        name (str): The module name for the logger.
        level (int): The log level for the logger. Default level set to INFO.

    Returns:
        Logger: A Python Logger object with custom configuration and formatting.

    """
    logger = getLogger(name)
    if len(logger.handlers) > 0:
        logger.handlers = []
    if level:
        logger.setLevel(level)

    sh = StreamHandler()
    if level:
        sh.setLevel(level)

    formatter = Formatter(
        fmt="%(asctime)s.%(msecs)03d - %(levelname)s - %(filename)s - %(name)s:%(lineno)d - %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S"
    )
    sh.setFormatter(formatter)

    logger.addHandler(sh)

    return logger