How to use the coloredlogs.DEFAULT_LOG_FORMAT 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 / tls-canary / tlscanary / scheduler / main.py View on Github external
import schedule
from shutil import which
from subprocess import check_output, CalledProcessError, run
import sys
import time

# Load Matplotlib in "headless" mode to prevent carnage
# CAVE: Every matplotlib property used by this code must be explicitly imported in the dummy
from .matplotlib_agg import matplotlib
from matplotlib.dates import datestr2num
import matplotlib.pyplot as plt

# Initialize coloredlogs
logging.Formatter.converter = time.gmtime
logger = logging.getLogger(__name__)
coloredlogs.DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s"
coloredlogs.install(level="INFO")


def list_logs(tlscanary: str, tag: str = "all") -> list:
    cmd = [tlscanary, "log", "-i", tag, "-e", "incomplete", "-e", "incompatible"]
    logger.info("Running `%s`" % " ".join(cmd))
    log_output = check_output(cmd).decode("utf-8").split("\n")[:-1]

    # Log reference is in leftmost column of output
    return list(sorted(map(lambda line: line.split("\t")[0], log_output)))


def get_log(tlscanary: str, ref: str) -> dict:
    cmd = [tlscanary, "log", "-a", "json", "-i", str(ref)]

    # Retries are necessary as EC2 instances are running into spurious BrokenPipe errors
github alexa-pi / AlexaPi / src / main.py View on Github external
config_exists = alexapi.config.filename is not None

if config_exists:
	with open(alexapi.config.filename, 'r') as stream:
		config = yaml.load(stream)

if debug:
	log_level = logging.DEBUG
else:
	if config_exists:
		log_level = logging.getLevelName(config.get('logging', 'INFO').upper())
	else:
		log_level = logging.getLevelName('INFO')

if cmdopts.daemon:
	coloredlogs.DEFAULT_LOG_FORMAT = '%(levelname)s: %(message)s'
else:
	coloredlogs.DEFAULT_LOG_FORMAT = '%(asctime)s %(levelname)s: %(message)s'

coloredlogs.install(level=log_level)
alexa_logger = logging.getLogger('alexapi')
alexa_logger.setLevel(log_level)

logger = logging.getLogger(__name__)

if not config_exists:
	logger.critical('Can not find configuration file. Exiting...')
	sys.exit(1)

# Setup event commands
event_commands = {
	'startup': "",
github alexa-pi / AlexaPi / src / main.py View on Github external
if config_exists:
	with open(alexapi.config.filename, 'r') as stream:
		config = yaml.load(stream)

if debug:
	log_level = logging.DEBUG
else:
	if config_exists:
		log_level = logging.getLevelName(config.get('logging', 'INFO').upper())
	else:
		log_level = logging.getLevelName('INFO')

if cmdopts.daemon:
	coloredlogs.DEFAULT_LOG_FORMAT = '%(levelname)s: %(message)s'
else:
	coloredlogs.DEFAULT_LOG_FORMAT = '%(asctime)s %(levelname)s: %(message)s'

coloredlogs.install(level=log_level)
alexa_logger = logging.getLogger('alexapi')
alexa_logger.setLevel(log_level)

logger = logging.getLogger(__name__)

if not config_exists:
	logger.critical('Can not find configuration file. Exiting...')
	sys.exit(1)

# Setup event commands
event_commands = {
	'startup': "",
	'pre_interaction': "",
	'post_interaction': "",
github ustwo / mastermind / mastermind / say.py View on Github external
from __future__ import (absolute_import, print_function, division)
import logging
import coloredlogs as cl


logger = logging.getLogger("mastermind")
cl.DEFAULT_FIELD_STYLES = {"name": {"color": "cyan"},
                           "levelname": {"color": "magenta"},
                           "asctime": {"color": "green"}}
cl.DEFAULT_LOG_FORMAT = "%(asctime)s %(name)s %(levelname)s %(message)s"


def level(x):
    levels = ['ERROR', 'WARNING', 'INFO', 'DEBUG']
    x = 3 if x > 3 else x

    cl.install(level=levels[x])
github aetros / aetros-cli / aetros / utils / __init__.py View on Github external
def get_logger(name='', debug=None, format=None):

    import coloredlogs
    # logging.basicConfig() # this will make paramiko log a lot of stuff
    logger = logging.getLogger(name if name else 'aetros')

    level = 'INFO'
    fmt = '%(message)s' if format is None else format

    if debug is None:
        debug = is_debug()

    if debug:
        level = 'DEBUG'
        if format is None:
            fmt = coloredlogs.DEFAULT_LOG_FORMAT

    atty = None
    if '1' == os.getenv('AETROS_ATTY'):
        atty = True

    coloredlogs.install(fmt=fmt, level=level, logger=logger, isatty=atty)

    return logger
github paylogic / pip-accel / pip_accel / config.py View on Github external
def log_format(self):
        """
        The format of log messages written to the terminal.

        - Environment variable: ``$PIP_ACCEL_LOG_FORMAT``
        - Configuration option: ``log-format``
        - Default: :data:`~coloredlogs.DEFAULT_LOG_FORMAT`
        """
        return self.get(property_name='log_format',
                        environment_variable='PIP_ACCEL_LOG_FORMAT',
                        configuration_option='log-format',
                        default=DEFAULT_LOG_FORMAT)
github mozilla / iris_firefox / iris / __main__.py View on Github external
from api.core.util.core_helper import *
from api.core.util.parse_args import get_global_args, parse_args
from api.core.util.test_loader import load_tests, scan_all_tests
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):
github mozilla / tls-canary / tlscanary / main.py View on Github external
import sys
import tempfile
import threading
import time

from tlscanary import loader
from tlscanary import modes
from tlscanary import sources_db as sdb
from tlscanary.tools import cleanup
from tlscanary.tools import firefox_downloader as fd


# Initialize coloredlogs
logging.Formatter.converter = time.gmtime
logger = logging.getLogger(__name__)
coloredlogs.DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s"
coloredlogs.install(level="INFO")


def parse_args(argv=None):
    """
    Argument parsing. Parses from sys.argv if argv is None.
    :param argv: argument vector to parse
    :return: parsed arguments
    """
    if argv is None:
        argv = sys.argv[1:]

    pkg_version = pkg_resources.require("tlscanary")[0].version
    home = os.path.expanduser("~")

    # Set up the parent parser with shared arguments
github mozilla / iris / moziris / util / logger_manager.py View on Github external
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
github picoCTF / picoCTF / picoCTF-shell / shell_manager / run.py View on Github external
import logging
from argparse import ArgumentParser

import coloredlogs
from hacksport.install import (
    install_problems,
    uninstall_problems,
    install_bundle,
    uninstall_bundle,
)
from hacksport.deploy import deploy_problems, undeploy_problems
from hacksport.status import clean, publish, status
from shell_manager.config import print_configuration, set_configuration_option
from shell_manager.util import FatalException

coloredlogs.DEFAULT_LOG_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s"
coloredlogs.DEFAULT_DATE_FORMAT = "%H:%M:%S"

logger = logging.getLogger(__name__)


def main():
    parser = ArgumentParser(description="Shell Manager")
    parser.add_argument(
        "-d",
        "--debug",
        action="store_true",
        default=False,
        help="show debug information",
    )
    parser.add_argument(
        "--colorize",