#!/usr/bin/env python

"""Custom format log"""

# System modules
import sys

# Third-party modules
from loguru import logger

# Custom modules
from directory.structure import log_path


def mylog():
    "logger function"

    logger.remove()

    time = "{time:YYYY-MM-DD HH:mm:ss.SSSSSS!UTC} "
    level = "<level>{level: <8}</level> "
    message = "| {message} "
    stack = "<bold>({module}.{function}:{line})</bold>"
    fmt = time + level + message + stack

    # On standard output
    logger.add(sys.stderr, format=fmt)

    # On file
    log_day = log_path("{time:YYYY-MM-DD!UTC}")
    logger.add(log_day, format=fmt, colorize=True, rotation="1 day")

    # Custom levels
    logger.level("DEBUG", color="<magenta><bold>")
    logger.level("INFO", color="<green><bold>")

    return logger


def main():
    """Main function"""

    log = mylog()

    log.debug("debug message")
    log.info("info message")
    log.warning("warning message")
    log.error("error message")
    log.critical("critical message")


if __name__ == "__main__":
    main()
else:
    log = mylog()
