How to use the coloredlogs.DEFAULT_LEVEL_STYLES function in coloredlogs

To help you get started, weā€™ve selected a few coloredlogs 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 mozilla / iris_firefox / iris / __main__.py View on Github external
from api.core.util.version_parser import get_latest_scraper_details, get_version_from_path, get_scraper_details
from api.helpers.general import launch_firefox, quit_firefox, get_firefox_channel, get_firefox_version, \
    get_firefox_build_id
from firefox import cleanup
from local_web_server import LocalWebServer
from test_runner import run

restore_terminal_encoding = None
LOG_FILENAME = 'iris_log.log'
LOG_FORMAT = '%(asctime)s [%(levelname)s] [%(name)s] %(message)s'
logger = logging.getLogger(__name__)

coloredlogs.DEFAULT_LOG_FORMAT = LOG_FORMAT
coloredlogs.DEFAULT_FIELD_STYLES = {'levelname': {'color': 'cyan', 'bold': True},
                                    'name': {'color': 'cyan', 'bold': True}}
coloredlogs.DEFAULT_LEVEL_STYLES = {'warning': {'color': 'yellow', 'bold': True},
                                    'success': {'color': 'green', 'bold': True},
                                    'error': {'color': 'red', 'bold': True}}


def main():
    """This is the main entry point defined in setup.py"""
    Iris()


class Iris(object):
    process_list = None

    def __init__(self):
        cleanup.init()
        Iris.fix_terminal_encoding()
        self.initialize_platform()
github icon-project / icon-service / iconservice / logger / configuration.py View on Github external
def __update_log_color_set(self, logger):
        coloredlogs.DEFAULT_FIELD_STYLES = {
            'hostname': {'color': 'magenta'},
            'programname': {'color': 'cyan'},
            'name': {'color': 'blue'},
            'levelname': {'color': 'black', 'bold': True},
            'asctime': {'color': 'magenta'}}

        coloredlogs.DEFAULT_LEVEL_STYLES = {
            'info': {'color': 'green'},
            'notice': {'color': 'magenta'},
            'verbose': {'color': 'blue'},
            'success': {'color': 'green', 'bold': True},
            'spam': {'color': 'cyan'},
            'critical': {'color': 'red', 'bold': True},
            'error': {'color': 'red'},
            'debug': {'color': 'white'},
            'warning': {'color': 'yellow'}}

        coloredlogs.install(logger=logger,
                            fmt=self.__log_format,
                            datefmt="%m-%d %H:%M:%S",
                            level=self.log_level,
                            milliseconds=True)
github chanzuckerberg / miniwdl / WDL / _util.py View on Github external
contextmanager to set up the root/stderr logger; yields a function to set the status line at
    the bottom of the screen (if stderr isatty, else it does nothing)
    """
    logger = logging.getLogger()

    if json:
        logger.handlers[0].setFormatter(StructuredLogMessageJSONFormatter())
        yield (lambda ignore: None)
    else:
        level_styles = {}
        field_styles = {}
        fmt = LOGGING_FORMAT
        tty = force_tty or (sys.stderr.isatty() and "NO_COLOR" not in os.environ)

        if tty:
            level_styles = dict(coloredlogs.DEFAULT_LEVEL_STYLES)
            level_styles["debug"]["color"] = 242
            level_styles["notice"] = {"color": "green", "bold": True}
            level_styles["error"]["bold"] = True
            level_styles["warning"]["bold"] = True
            level_styles["info"] = {}
            field_styles = dict(coloredlogs.DEFAULT_FIELD_STYLES)
            field_styles["asctime"] = {"color": "blue"}
            field_styles["name"] = {"color": "magenta"}
            fmt = COLORED_LOGGING_FORMAT

            # monkey-patch _StatusLineStandardErrorHandler over coloredlogs.StandardErrorHandler for
            # coloredlogs.install() to instantiate
            coloredlogs.StandardErrorHandler = _StatusLineStandardErrorHandler
            sys.stderr.write(ANSI.HIDE_CURSOR)  # hide cursor

        try:
github CNR-Engineering / PyTelTools / pyteltools / utils / log.py View on Github external
import coloredlogs
import logging

from pyteltools.conf import settings


# Overwrite some default styles
try:
    has_bold = coloredlogs.CAN_USE_BOLD_FONT  # coloredlogs<14.0 (old versions)
except AttributeError:
    has_bold = True
LEVEL_STYLES = coloredlogs.DEFAULT_LEVEL_STYLES
FIELD_STYLES = coloredlogs.DEFAULT_FIELD_STYLES
FIELD_STYLES['levelname'] = {'color': 'white', 'bold': has_bold}  # Avoid 'black' color for Windows


# Create a logger object
def new_logger(name):
    """!
    Get a new logger
    @param name : logger name
    """
    logger = logging.getLogger(name)
    if settings.COLOR_LOGS:
        coloredlogs.install(logger=logger, level=settings.LOGGING_LEVEL, fmt=settings.LOGGING_FMT_CLI,
                            level_styles=LEVEL_STYLES, field_styles=FIELD_STYLES)
    else:
        handler = logging.StreamHandler()
github alexa-pi / AlexaPi / src / main.py View on Github external
import alexapi.config
import alexapi.tunein as tunein
import alexapi.capture
import alexapi.triggers as triggers
from alexapi.exceptions import ConfigurationException
from alexapi.constants import RequestType, PlayerActivity

logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s')
coloredlogs.DEFAULT_FIELD_STYLES = {
	'hostname': {'color': 'magenta'},
	'programname': {'color': 'cyan'},
	'name': {'color': 'blue'},
	'levelname': {'color': 'magenta', 'bold': True},
	'asctime': {'color': 'green'}
}
coloredlogs.DEFAULT_LEVEL_STYLES = {
	'info': {'color': 'blue'},
	'critical': {'color': 'red', 'bold': True},
	'error': {'color': 'red'},
	'debug': {'color': 'green'},
	'warning': {'color': 'yellow'}
}

# Get arguments
parser = optparse.OptionParser()
parser.add_option('-s', '--silent',
		dest="silent",
		action="store_true",
		default=False,
		help="start without saying hello")
parser.add_option('-d', '--debug',
		dest="debug",
github icon-project / loopchain / loopchain / utils / loggers / configuration.py View on Github external
'levelname': {'color': 'black', 'bold': True},
            'asctime': {'color': 'magenta'}}

        if self.is_leader:
            coloredlogs.DEFAULT_LEVEL_STYLES = {
                'info': {},
                'notice': {'color': 'magenta'},
                'verbose': {'color': 'green'},
                'success': {'color': 'green', 'bold': True},
                'spam': {'color': 'cyan'},
                'critical': {'color': 'red', 'bold': True},
                'error': {'color': 'red'},
                'debug': {'color': 'blue'},
                'warning': {'color': 'yellow'}}
        else:
            coloredlogs.DEFAULT_LEVEL_STYLES = {
                'info': {},
                'notice': {'color': 'magenta'},
                'verbose': {'color': 'blue'},
                'success': {'color': 'green', 'bold': True},
                'spam': {'color': 'cyan'},
                'critical': {'color': 'red', 'bold': True},
                'error': {'color': 'red'},
                'debug': {'color': 'green'},
                'warning': {'color': 'yellow'}}

        coloredlogs.install(logger=logger,
                            fmt=self._log_format,
                            datefmt="%Y-%m-%d %H:%M:%S",
                            level=self._log_level)