#!/usr/bin/env python

"""Custom format"""

# System modules
import sys
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} "
    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)

    logfile = log_path("{time:YYYY-MM-DD}.log")
    logger.add(logfile, format=fmt, colorize=True)

    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")


def log_prefix(func):
    def inner_function(*args, **kwargs):
        # add a prefix based on used Template name
        return func(*args, **kwargs)
    return inner_function


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