How to use the colorlog.LevelFormatter function in colorlog

To help you get started, we’ve selected a few colorlog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github robingall2910 / RobTheBoat / utils / logger.py View on Github external
def init():
        if len(logging.getLogger("").handlers) > 1:
            return

        shandler = logging.StreamHandler(stream=sys.stdout)
        shandler.setFormatter(colorlog.LevelFormatter(
            fmt = {
                "DEBUG": "{log_color}[{levelname}] {message}",
                "INFO": "{log_color}[{levelname}] {message}",
                "WARNING": "{log_color}[{levelname}] {message}",
                "ERROR": "{log_color}[{levelname}] {message}",
                "CRITICAL": "{log_color}[{levelname}] {message}"
            },
            log_colors = {
                "DEBUG": "cyan",
                "INFO": "white",
                "WARNING": "yellow",
                "ERROR": "red",
                "CRITICAL": "bold_red"
        },
            style = "{",
            datefmt = ""
github ZeroEpoch1969 / RubyRoseBot / utils / logger.py View on Github external
def init():
        if len(logging.getLogger("").handlers) > 1:
            return

        shandler = logging.StreamHandler(stream=sys.stdout)
        shandler.setFormatter(colorlog.LevelFormatter(
            fmt = {
                "DEBUG": "{log_color}[{levelname}] {message}",
                "INFO": "{log_color}[{levelname}] {message}",
                "WARNING": "{log_color}[{levelname}] {message}",
                "ERROR": "{log_color}[{levelname}] {message}",
                "CRITICAL": "{log_color}[{levelname}] {message}"
            },
            log_colors = {
                "DEBUG": "cyan",
                "INFO": "white",
                "WARNING": "yellow",
                "ERROR": "red",
                "CRITICAL": "bold_red"
        },
            style = "{",
            datefmt = ""
github ELEKTRONN / elektronn3 / elektronn3 / logger.py View on Github external
lfile_formatter = logging.Formatter(
            '[%(asctime)s] [%(levelname)s]\t%(message)s',
            datefmt='%Y-%m-%d %H:%M:%S')
        uu = uuid.uuid4()
        # Temporary log file path, to be changed later.
        lfile_path = os.path.abspath(f'/tmp/{user_name}_{uu}_elektronn3.log')
        lfile_level = logging.DEBUG
        lfile_handler = logging.FileHandler(lfile_path)
        lfile_handler.setLevel(lfile_level)
        lfile_handler.setFormatter(lfile_formatter)
        logger.addHandler(lfile_handler)

        lstream_handler = colorlog.StreamHandler(sys.stdout)
        lstream_handler.setFormatter(
            colorlog.LevelFormatter(fmt=log_level_formats,
                                    log_colors=log_colors))
        # set this to logging.DEBUG to enable output for logger.debug() calls
        lstream_level = logging.INFO
        lstream_handler.setLevel(lstream_level)
        logger.addHandler(lstream_handler)

        logger.propagate = False

        if False:  # Test log levels:
            logger.critical('== critical')
            logger.error('== error')
            logger.warning('== warn')
            logger.info('== info')
            logger.debug('== debug')
github Just-Some-Bots / MusicBot / musicbot / bot.py View on Github external
def _setup_logging(self):
        if len(logging.getLogger(__package__).handlers) > 1:
            log.debug("Skipping logger setup, already set up")
            return

        shandler = logging.StreamHandler(stream=sys.stdout)
        shandler.setFormatter(colorlog.LevelFormatter(
            fmt = {
                'DEBUG': '{log_color}[{levelname}:{module}] {message}',
                'INFO': '{log_color}{message}',
                'WARNING': '{log_color}{levelname}: {message}',
                'ERROR': '{log_color}[{levelname}:{module}] {message}',
                'CRITICAL': '{log_color}[{levelname}:{module}] {message}',

                'EVERYTHING': '{log_color}[{levelname}:{module}] {message}',
                'NOISY': '{log_color}[{levelname}:{module}] {message}',
                'VOICEDEBUG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}',
                'FFMPEG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}'
            },
            log_colors = {
                'DEBUG':    'cyan',
                'INFO':     'white',
                'WARNING':  'yellow',
github helionmusic / rhinobot_heroku / musicbot / bot.py View on Github external
def _setup_logging(self):
        if len(logging.getLogger(__package__).handlers) > 1:
            log.debug("Skipping logger setup, already set up")
            return

        shandler = logging.StreamHandler(stream=sys.stdout)
        shandler.setFormatter(colorlog.LevelFormatter(
            fmt = {
                'DEBUG': '{log_color}[{levelname}:{module}] {message}',
                'INFO': '{log_color}{message}',
                'WARNING': '{log_color}{levelname}: {message}',
                'ERROR': '{log_color}[{levelname}:{module}] {message}',
                'CRITICAL': '{log_color}[{levelname}:{module}] {message}',

                'EVERYTHING': '{log_color}[{levelname}:{module}] {message}',
                'NOISY': '{log_color}[{levelname}:{module}] {message}',
                'VOICEDEBUG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}',
                'FFMPEG': '{log_color}[{levelname}:{module}][{relativeCreated:.9f}] {message}'
            },
            log_colors = {
                'DEBUG':    'cyan',
                'INFO':     'white',
                'WARNING':  'yellow',
github ELEKTRONN / ELEKTRONN2 / elektronn2 / __init__.py View on Github external
logger.setLevel(logging.DEBUG)

    lfile_formatter = logging.Formatter(
        '[%(asctime)s] [%(levelname)s]\t%(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    lfile_path = os.path.abspath('/tmp/{}_elektronn2.log'.format(user_name))
    lfile_level = logging.DEBUG
    lfile_handler = logging.FileHandler(lfile_path)
    lfile_handler.setLevel(lfile_level)
    lfile_handler.setFormatter(lfile_formatter)
    logger.addHandler(lfile_handler)

    if colorize:
        lstream_handler = colorlog.StreamHandler(sys.stdout)
        lstream_handler.setFormatter(
            colorlog.LevelFormatter(fmt=log_level_formats,
                                    log_colors=log_colors))
    else:
        lstream_handler = logging.StreamHandler(sys.stdout)
    # set this to logging.DEBUG to enable output for logger.debug() calls
    lstream_level = logging.INFO
    lstream_handler.setLevel(lstream_level)
    logger.addHandler(lstream_handler)

    logger.propagate = False

    if False:  # Test log levels:
        logger.critical('== critical')
        logger.error('== error')
        logger.warning('== warn')
        logger.info('== info')
        logger.debug('== debug')