当前位置: 首页>>代码示例>>Python>>正文


Python rainbow_logging_handler.RainbowLoggingHandler类代码示例

本文整理汇总了Python中rainbow_logging_handler.RainbowLoggingHandler的典型用法代码示例。如果您正苦于以下问题:Python RainbowLoggingHandler类的具体用法?Python RainbowLoggingHandler怎么用?Python RainbowLoggingHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RainbowLoggingHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_console_logging

def setup_console_logging(log_level=None):
    """Setup console logging.

    Aimed to give easy sane defaults for loggig in command line applications.

    Don't use logging settings from INI, but use hardcoded defaults.
    """

    formatter = logging.Formatter("[%(asctime)s] [%(name)s %(funcName)s] %(message)s")  # same as default

    # setup `RainbowLoggingHandler`
    # and quiet some logs for the test output
    handler = RainbowLoggingHandler(sys.stdout)
    handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.handlers = [handler]

    env_level = os.environ.get("LOG_LEVEL", "info")
    log_level = log_level or getattr(logging, env_level.upper())
    logger.setLevel(log_level)

    logger = logging.getLogger("requests.packages.urllib3.connectionpool")
    logger.setLevel(logging.ERROR)

    # SQL Alchemy transactions
    logger = logging.getLogger("txn")
    logger.setLevel(logging.ERROR)
开发者ID:arianmaykon,项目名称:websauna,代码行数:27,代码来源:cmdline.py

示例2: test_format_all_column

def test_format_all_column():
    logger = logging.getLogger('test_logging_format_all_column')
    logger.setLevel(logging.DEBUG)

    formatter = logging.Formatter('''
        name            = '%(name)s'
        levelno         = '%(levelno)s'
        levelname       = '%(levelname)s'
        pathname        = '%(pathname)s'
        filename        = '%(filename)s'
        module          = '%(module)s'
        lineno          = '%(lineno)d'
        funcName        = '%(funcName)s'
        created         = '%(created)f'
        asctime         = '%(asctime)s'
        msecs           = '%(msecs)d'
        relativeCreated = '%(relativeCreated)d'
        thread          = '%(thread)d'
        threadName      = '%(threadName)s'
        process         = '%(process)d'
        message         = '%(message)s'
    ''')

    handler = RainbowLoggingHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    logger.debug("debug msg")
开发者ID:GNSASE,项目名称:auto_ndt,代码行数:28,代码来源:test_logging.py

示例3: setup

def setup():
    formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default

    # setup `RainbowLoggingHandler`
    # and quiet some logs for the test output
    handler = RainbowLoggingHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.addHandler(handler)

    if "VERBOSE_TEST" in os.environ:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.ERROR)

    logger = logging.getLogger("requests.packages.urllib3.connectionpool")
    logger.setLevel(logging.ERROR)

    logger = logging.getLogger("cryptoassets.core.backend.blockio")
    logger.setLevel(logging.DEBUG)

    logger = logging.getLogger("cryptoassets.core.backend.bitcoind")
    logger.setLevel(logging.WARN)

    # SQL Alchemy transactions
    logger = logging.getLogger("txn")
    logger.setLevel(logging.ERROR)
开发者ID:ejakait,项目名称:bitkoin,代码行数:27,代码来源:testlogging.py

示例4: setup_custom_logger

def setup_custom_logger():
    LOG_FILE = 'log/cpa'

    formatter = logging.Formatter("[%(asctime)s] %(threadName)s - %(pathname)s %(funcName)s():%(lineno)d  %(levelname)s \t%(message)s")  # same as default
    # formatter = logging.Formatter('%(asctime)s [%(pathname)s: %(lineno)d] %(levelname)s %(message)s')

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    file_handler = ParallelTimedRotatingFileHandler(LOG_FILE, when='H')
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    # console_handler = logging.StreamHandler(sys.stdout)
    # console_handler.formatter = formatter
    # logger.addHandler(console_handler)

    # setup `RainbowLoggingHandler`
    handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    #Add file handler
    handler = TimedRotatingFileHandler(LOG_FILE,
                                       when="h",
                                       interval=1,
                                       backupCount=48)

    # try:
    #     raise RuntimeError("Opa!")
    # except Exception as e:
    #     logger.exception(e)

    return logger
开发者ID:ThinkmanWang,项目名称:CPATCPServer,代码行数:34,代码来源:log.py

示例5: setup_logging

def setup_logging():
    log = logging.getLogger("")
    handler = RainbowLoggingHandler(sys.stderr)
    handler._column_color['%(asctime)s'] = ('cyan', None, False)
    handler._column_color['%(levelname)-7s'] = ('green', None, False)
    handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
    log.addHandler(handler)
    log.setLevel(logging.INFO)
开发者ID:delfick,项目名称:cloudcity,代码行数:9,代码来源:executor.py

示例6: logger

def logger(config_file):
    CONFIG = configparser.RawConfigParser()

    CONFIG.read(config_file)

    logger_config = CONFIG['logger']

    logger = logging.getLogger(logger_config['name'])

    logger.setLevel(LOGGING_LEVELS.get(logger_config['level'], logging.NOTSET))

    formatter = logging.Formatter(
        '[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s'
    )

    handler = RainbowLoggingHandler(
        sys.stderr,
        color_funcName=('black', 'yellow', True)
    )

    handler.setFormatter(formatter)

    logger.addHandler(handler)

    if CONFIG.has_section('file_logger'):
        file_logger_config = CONFIG['file_logger']

        fh = logging.handlers.RotatingFileHandler(
            file_logger_config['file_path'],
            maxBytes=int(file_logger_config['max_log_file_size']),
            backupCount=int(file_logger_config['backup_count'])
        )

        fh.setLevel(LOGGING_LEVELS.get(file_logger_config['level'],
                                       logging.NOTSET))
        fh.setFormatter(formatter)
        logger.addHandler(fh)

    if CONFIG.has_section('email_logger'):
        email_logger_config = CONFIG['email_logger']

        eh = logging.handlers.SMTPHandler(
            (email_logger_config['host'], email_logger_config['port']),
            email_logger_config['from'],
            email_logger_config['to'],
            email_logger_config['subject'],
            (email_logger_config['username'], email_logger_config['password']),
            ()
        )

        eh.setLevel(LOGGING_LEVELS.get(email_logger_config['level'],
                                       logging.NOTSET))
        eh.setFormatter(formatter)
        logger.addHandler(eh)

    return logger
开发者ID:jvmsangkal,项目名称:freedom_python_logger,代码行数:56,代码来源:__init__.py

示例7: add_stdout_handler

def add_stdout_handler(logger, formatter):
    try:
        from rainbow_logging_handler import RainbowLoggingHandler
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=(
            'black', 'black', True))
    except ImportError:
        handler = logging.StreamHandler()
        pass

    handler.setFormatter(formatter)
    logger.addHandler(handler)
开发者ID:Zopieux,项目名称:touchandgo,代码行数:11,代码来源:logger.py

示例8: setup_logging

def setup_logging(verbose=False):
    log = logging.getLogger("")
    handler = RainbowLoggingHandler(sys.stderr)
    handler._column_color['%(asctime)s'] = ('cyan', None, False)
    handler._column_color['%(levelname)-7s'] = ('green', None, False)
    handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
    log.addHandler(handler)
    log.setLevel([logging.INFO, logging.DEBUG][verbose])

    logging.getLogger("boto").level = logging.CRITICAL
开发者ID:realestate-com-au,项目名称:iam_syncr,代码行数:11,代码来源:executor.py

示例9: setup

def setup():
    # prepare log file
    global f_log, logpath
    (fd, logpath) = mkstemp(prefix='raibow-', suffix='.txt')
    f_log = os.fdopen(fd, 'w')

    # prepare 'test_format' logger
    logger = logging.getLogger('test_format')
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("AAA %(name)s - %(levelname)s - %(message)s ZZZ")  # testing whether this format is used

    handler = RainbowLoggingHandler(f_log)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
开发者ID:GNSASE,项目名称:auto_ndt,代码行数:14,代码来源:test_format.py

示例10: setup_logging

def setup_logging(verbose=False, silent=False, debug=False):
    log = logging.getLogger("")
    handler = RainbowLoggingHandler(sys.stderr)
    handler._column_color['%(asctime)s'] = ('cyan', None, False)
    handler._column_color['%(levelname)-7s'] = ('green', None, False)
    handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
    log.addHandler(handler)
    log.setLevel([logging.INFO, logging.DEBUG][verbose or debug])
    if silent:
        log.setLevel(logging.ERROR)

    logging.getLogger("requests").setLevel([logging.CRITICAL, logging.ERROR][verbose or debug])
    return handler
开发者ID:CaseyLeask,项目名称:harpoon,代码行数:14,代码来源:executor.py

示例11: test_custom_format

def test_custom_format():
    logger = logging.getLogger('test_logging_custom_format')
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("MESSAGE ONLY => %(message)s")

    handler = RainbowLoggingHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    logger.debug("debug msg")
    logger.info("info msg")
    logger.warn("warn msg")
    logger.error("error msg")
    logger.critical("critical msg")
开发者ID:GNSASE,项目名称:auto_ndt,代码行数:14,代码来源:test_logging.py

示例12: get_logger

def get_logger():
    global logger
    
    if logger == None:
        logger = logging.getLogger('freesprints')
        logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default
        
        # setup colored logging
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
        handler.setFormatter(formatter)
        logger.addHandler(handler)
    
    return logger
开发者ID:niklasberglund,项目名称:freesprints,代码行数:14,代码来源:__init__.py

示例13: __init__

    def __init__(self, module_name):
        self.logger_tmp = None
        logger = logging.getLogger(module_name)
        logging.basicConfig(filename='/tmp/r2als.log',level=logging.DEBUG,format='%(asctime)s %(levelname)s %(message)s')
        # logging.basicConfig(level=logging.DEBUG)
        formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default

         # setup `RainbowLoggingHandler`
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'gray', True))
        handler.setFormatter(formatter)

        logger.addHandler(handler)

        self.logger_tmp = logger
开发者ID:mildronize,项目名称:R2ALS,代码行数:14,代码来源:logs.py

示例14: add_stdout_handler

def add_stdout_handler(logger):
    formatter = Formatter(
        "[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")
    try:
        # Si está instalado rainbow_logging_handler (coloriza el output
        # de consola) lo usamos, sino defaulteamos al módulo logging
        from rainbow_logging_handler import RainbowLoggingHandler
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=(
            'black', 'black', True))
    except ImportError:
        handler = StreamHandler()
        pass

    handler.setFormatter(formatter)
    logger.addHandler(handler)
开发者ID:bauna,项目名称:vot.ar,代码行数:15,代码来源:__init__.py

示例15: setup_logging

    def setup_logging(self, args, verbose=False, silent=False, debug=False, logging_name=""):
        """Setup the RainbowLoggingHandler for the logs and call setup_other_logging"""
        log = logging.getLogger(logging_name)
        handler = RainbowLoggingHandler(self.logging_handler_file)
        handler._column_color['%(asctime)s'] = ('cyan', None, False)
        handler._column_color['%(levelname)-7s'] = ('green', None, False)
        handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
        handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
        log.addHandler(handler)
        log.setLevel([logging.INFO, logging.DEBUG][verbose or debug])
        if silent:
            log.setLevel(logging.ERROR)

        self.setup_other_logging(args, verbose, silent, debug)
        return handler
开发者ID:jonhiggs,项目名称:delfick_app,代码行数:15,代码来源:delfick_app.py


注:本文中的rainbow_logging_handler.RainbowLoggingHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。