Python coloredlogs.DEFAULT_FIELD_STYLES Examples

The following are 4 code examples of coloredlogs.DEFAULT_FIELD_STYLES(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module coloredlogs , or try the search function .
Example #1
Source File: logger_manager.py    From iris with Mozilla Public License 2.0 6 votes vote down vote up
def set_log_format():

    if core_args.level < 20:
        log_format = "%(asctime)s [%(levelname)s] %(message)s"
        coloredlogs.DEFAULT_LOG_FORMAT = log_format
        coloredlogs.DEFAULT_FIELD_STYLES = {
            "levelname": {"color": "cyan", "bold": True}
        }
        coloredlogs.DEFAULT_LEVEL_STYLES = {
            "warning": {"color": "yellow", "bold": True},
            "success": {"color": "green", "bold": True},
            "error": {"color": "red", "bold": True},
        }
    else:
        log_format = "%(message)s"
        coloredlogs.DEFAULT_LOG_FORMAT = log_format
        coloredlogs.DEFAULT_LEVEL_STYLES = {
            "warning": {"color": "yellow", "bold": True},
            "success": {"color": "green", "bold": True},
            "error": {"color": "red", "bold": True},
        }
    return log_format 
Example #2
Source File: logger.py    From dynamite-nsm with GNU General Public License v3.0 6 votes vote down vote up
def get_logger(component_name, level=logging.INFO, stdout=True):
    coloredlogs.DEFAULT_FIELD_STYLES = {'asctime': {'color': 'green'}, 'hostname': {'color': 'magenta'},
                                        'levelname': {'bold': True, 'color': 'black'},
                                        'name': {'color': 'cyan', 'bold': True},
                                        'programname': {'color': 'blue'}, 'username': {'color': 'yellow'}}

    utilities.makedirs(const.LOG_PATH, exist_ok=True)
    today_formatted_date = datetime.strftime(datetime.today(), '%d-%m-%Y')
    logger = logging.getLogger(component_name)
    logger.setLevel(level)
    if not len(logger.handlers):
        fh = logging.FileHandler(os.path.join(const.LOG_PATH, 'dynamite-{}.log'.format(today_formatted_date)))
        fformatter = logging.Formatter(
            '%(asctime)s | %(name)15s | %(module)20s | %(funcName)45s | %(lineno)4s | %(levelname)8s |  %(message)s')
        fh.setFormatter(fformatter)
        logger.addHandler(fh)
    if stdout:
        coloredlogs.install(level=level, logger=logger,
                            fmt='%(asctime)s %(name)-15s %(levelname)-10s | %(message)s')
    logger.propagate = False
    return logger 
Example #3
Source File: util.py    From spotify-downloader with MIT License 5 votes vote down vote up
def install_logger(level, to_disable=("chardet", "urllib3", "spotipy", "pytube")):
    for module in to_disable:
        logging.getLogger(module).setLevel(logging.CRITICAL)
    if level == logging.DEBUG:
        fmt = "%(levelname)s:%(name)s:%(lineno)d:\n%(message)s\n"
    else:
        fmt = "%(levelname)s: %(message)s"
    logging.basicConfig(format=fmt, level=level)
    coloredlogs.DEFAULT_FIELD_STYLES = {
        "levelname": {"bold": True, "color": "yellow"},
        "name": {"color": "blue"},
        "lineno": {"color": "magenta"},
    }
    coloredlogs.install(level=level, fmt=fmt, logger=logger) 
Example #4
Source File: configuration.py    From loopchain with Apache License 2.0 5 votes vote down vote up
def _update_log_color_set(self, logger):
        # level SPAM value is 5
        # level DEBUG value is 10
        coloredlogs.DEFAULT_FIELD_STYLES = {
            'hostname': {'color': 'magenta'},
            'programname': {'color': 'cyan'},
            'name': {'color': 'blue'},
            '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)