How to use the colorlog.StreamHandler 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 nathan-v / aws_okta_keyman / aws_okta_keyman / __main__.py View on Github external
def entry_point():
    """Zero-argument entry point for use with setuptools/distribute."""
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    handler = colorlog.StreamHandler()
    fmt = (
        '%(asctime)-8s (%(bold)s%(log_color)s%(levelname)s%(reset)s) '
        '%(message)s')
    formatter = colorlog.ColoredFormatter(fmt, datefmt='%H:%M:%S')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    keyman = Keyman(sys.argv)
    raise SystemExit(keyman.main())
github jiangsir404 / wam-monitor / log.py View on Github external
#!/usr/bin/env python        
#coding:utf-8

import os
import colorlog
import logging
from logging import handlers

log_path = 'logs'
if os.path.isdir(log_path) is not True:
    os.mkdir(log_path, 0o755)
logfile = os.path.join(log_path, 'wam.log')

handler = colorlog.StreamHandler()
formatter = colorlog.ColoredFormatter(
    '%(log_color)s%(asctime)s [%(name)s] [%(levelname)s] %(message)s%(reset)s',
    datefmt=None,
    reset=True,
    log_colors={
        'DEBUG': 'cyan',
        'INFO': 'green',
        'WARNING': 'yellow',
        'ERROR': 'red',
        'CRITICAL': 'red,bg_white'
    },
    secondary_log_colors={},
    style='%'
)
handler.setFormatter(formatter)
github energywebfoundation / ew-link-origin / deploy.py View on Github external
from requests import ReadTimeout

from lib import Spinner

CONTRACT_PATH = 'smart_contracts/data_logger.sol'
CONTRACT_NAME = 'DataLogger'
ACCOUNT = '0x00E27b1BB824D66d8ec926f23b04913Fe9b1Bd77'
PASSWORD = '48qzjbhPdZnw'

CONSTRUCTOR = ['siemens', 's5', 'c3dXokd09']

MAX_RETRIES = 100
SECONDS_BETWEEN_RETRIES = 2

handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(message)s'))
# Default color scheme is 'example'
logger = colorlog.getLogger('example')
logger.addHandler(handler)


class AsyncClientError(EnvironmentError):
    pass


print("\
*************************************************************\n\
*           Energy Web Foundation Contract Deployer         *\n\
*                      http://energyweb.org/                *\n\
*                                                           *\n\
*            Copyright © 2017 All rights reserved.          *\n\
github ELEKTRONN / elektronn3 / elektronn3 / logger.py View on Github external
if not len(logger.handlers) > 0:
        logger.setLevel(logging.DEBUG)

        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 APSL / rasengan / rasengan / main.py View on Github external
def initiate_log(loglevel):
    global log
    handler = colorlog.StreamHandler()
    formatter = colorlog.ColoredFormatter(
        "%(asctime)s %(log_color)s%(levelname)-8s%(reset)s %(log_color)s%(message)s",
        datefmt=None,
        reset=True,
        log_colors={
            'DEBUG':    'cyan',
            'INFO':     'green',
            'WARNING':  'yellow',
            'ERROR':    'red',
            'CRITICAL': 'red,bg_white',
        },
        secondary_log_colors={},
        style='%'
    )
    handler.setFormatter(formatter)
    log = colorlog.getLogger('rasengan')
github ajenhl / tacl / tacl / cli / utils.py View on Github external
def configure_logging(verbose, logger):
    """Configures the logging used."""
    if not verbose:
        log_level = logging.WARNING
    elif verbose == 1:
        log_level = logging.INFO
    else:
        log_level = logging.DEBUG
    logger.setLevel(log_level)
    ch = colorlog.StreamHandler()
    ch.setLevel(log_level)
    formatter = colorlog.ColoredFormatter(
        '%(log_color)s%(asctime)s %(name)s %(levelname)s: %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
github FeeiCN / ESD / ESD / __init__.py View on Github external
import base64
from tqdm import *
from shodan import Shodan
from shodan.cli.helpers import get_api_key
from optparse import OptionParser
import urllib.parse as urlparse
from collections import Counter
from aiohttp.resolver import AsyncResolver
from itertools import islice
from difflib import SequenceMatcher

__version__ = '0.0.24'

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

handler = colorlog.StreamHandler()
formatter = colorlog.ColoredFormatter(
    '%(log_color)s%(asctime)s [%(name)s] [%(levelname)s] %(message)s%(reset)s',
    datefmt=None,
    reset=True,
    log_colors={
        'DEBUG': 'cyan',
        'INFO': 'green',
        'WARNING': 'yellow',
        'ERROR': 'red',
        'CRITICAL': 'red,bg_white',
    },
    secondary_log_colors={},
    style='%'
)
handler.setFormatter(formatter)
github tijme / angularjs-csti-scanner / acstis_scripts / acstis_cli.py View on Github external
def setup_logger():
    """Setup ColorLog to enable colored logging output."""

    # Colored logging
    handler = colorlog.StreamHandler()
    handler.setFormatter(colorlog.ColoredFormatter(
        "%(log_color)s[%(levelname)s] %(message)s",
        log_colors={
            "DEBUG": "cyan",
            "INFO": "white",
            "SUCCESS": "green",
            "WARNING": "yellow",
            "ERROR": "red",
            "CRITICAL": "red,bg_white"
        }
    ))

    logger = colorlog.getLogger()
    logger.addHandler(handler)

    # Also show INFO logs
github bandrel / OCyara / ocyara / ocyara.py View on Github external
self.results = {}
        self.threads = worker_count
        self.lock = Lock()
        self.workers = []
        if os.path.isdir(self.path):
            if self.path[-1] is '/':
                self.path += '*'
            else:
                self.path += '/*'
        self.manager = Manager()
        self.matchedfiles = None
        self.total_items_to_queue = None
        self.total_added_to_queue = None
        self.queue_items_completed = None
        self.tempdir = tempfile.TemporaryDirectory()
        handler = colorlog.StreamHandler()
        handler.setFormatter(colorlog.ColoredFormatter(
                '%(log_color)s%(levelname)s:%(name)s:%(message)s'))
        self.logger = colorlog.getLogger('OCyara')
        self.logger.addHandler(handler)
        if verbose == 1:
            self.logger.setLevel('INFO')
        elif verbose > 1:
            self.logger.setLevel('DEBUG')
        else:
            self.logger.setLevel('WARN')
github koenvervloesem / hermes-audio-server / src / hermes_audio_server / logger.py View on Github external
def get_logger(command, verbose, daemon):
    """Return a Logger object with the right level, formatter and handler."""

    if daemon:
        handler = SysLogHandler(address=get_domain_socket())
        formatter = logging.Formatter(fmt=DAEMON_FORMAT.format(command))
        logger = logging.getLogger(command)
    else:
        handler = colorlog.StreamHandler(stream=sys.stdout)
        formatter = colorlog.ColoredFormatter(INTERACTIVE_FORMAT,
                                              log_colors=LOG_COLORS)
        logger = colorlog.getLogger(command)

    if verbose:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    handler.setFormatter(formatter)
    logger.addHandler(handler)

    return logger