# -*- coding: utf-8 -*-
import logging

import coloredlogs

__all__ = ['CustomLogger']

coloredlogs.DEFAULT_LOG_FORMAT = '%(asctime)s %(name)-12s \t %(levelname)-8s %(message)s'
SPAM = 5
VERBOSE = 15

logger = logging.getLogger(__name__)

# https://stackoverflow.com/questions/2183233/how-to-add-a-custom-loglevel-to-pythons-logging-facility

# https://pypi.org/project/coloredlogs/
# https://pypi.org/project/verboselogs/
# https://pypi.org/project/colorama/

class CustomLogger(logging.Logger):

    def __init__(self, name, level=logging.NOTSET):
        super().__init__(name, level)
        logging.addLevelName(VERBOSE, "VERBOSE")
        logging.addLevelName(SPAM, "SPAM")

    def verbose(self, msg, *args, **kwargs):
        if self.isEnabledFor(VERBOSE):
            self._log(VERBOSE, msg, args, **kwargs)

    def spam(self, msg, *args, **kwargs):
        if self.isEnabledFor(SPAM):
            self._log(SPAM, msg, args, **kwargs)


logging.setLoggerClass(CustomLogger)


def update(level='INFO'):
    coloredlogs.install(level=level)
    logger.debug(f"Log level: {level}")
