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


Python colorlog.ColoredFormatter方法代码示例

本文整理汇总了Python中colorlog.ColoredFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python colorlog.ColoredFormatter方法的具体用法?Python colorlog.ColoredFormatter怎么用?Python colorlog.ColoredFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colorlog的用法示例。


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

示例1: create_console_handler

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def create_console_handler(verbose_level):
    '''Setup console logging.'''
    del verbose_level # unused
    clog = logging.StreamHandler()
    formatter = ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
        "%(white)s%(message)s",
        datefmt="%H:%M:%S",
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red',
        })

    clog.setFormatter(formatter)
    clog.setLevel(logging.DEBUG)
    return clog 
开发者ID:danintel,项目名称:sawtooth-cookiejar,代码行数:22,代码来源:cookiejar.py

示例2: logger_config

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def logger_config(name=None):
    import logging
    import colorlog
    """
        Setup the logging environment
    """
    if not name:
        log = logging.getLogger()  # root logger
    else:
        log = logging.getLogger(name)
    log.setLevel(logging.INFO)
    format_str = '%(asctime)s.%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s'
    date_format = '%Y-%m-%d %H:%M:%S'
    cformat = '%(log_color)s' + format_str
    colors = {'DEBUG': 'green',
              'INFO': 'cyan',
              'WARNING': 'bold_yellow',
              'ERROR': 'bold_red',
              'CRITICAL': 'bold_purple'}
    formatter = colorlog.ColoredFormatter(cformat, date_format,
                                          log_colors=colors)
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)
    log.addHandler(stream_handler)
    return log 
开发者ID:int-brain-lab,项目名称:ibllib,代码行数:27,代码来源:misc.py

示例3: InitiateColorLogger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def InitiateColorLogger(name='twisted'):
    from colorlog import ColoredFormatter

    logger = logging.getLogger(name)

    stream = logging.StreamHandler()

    LogFormat = "  %(reset)s%(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s"
    stream.setFormatter(ColoredFormatter(LogFormat, log_colors={
        'DEBUG':    'white',
        'INFO':     'cyan',
        'WARNING':  'yellow',
        'ERROR':    'red',
        'CRITICAL': 'black,bg_red',
    }))

    logger.addHandler(stream)
    logger.setLevel(logging.DEBUG)

    logger.info("Porter running")
    return logger 
开发者ID:Times-0,项目名称:Timeline,代码行数:23,代码来源:DatabasePort.py

示例4: create_console_handler

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def create_console_handler(verbose_level):
    clog = logging.StreamHandler()
    formatter = ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
        "%(white)s%(message)s",
        datefmt="%H:%M:%S",
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red',
        })

    clog.setFormatter(formatter)

    if verbose_level == 0:
        clog.setLevel(logging.WARN)
    elif verbose_level == 1:
        clog.setLevel(logging.INFO)
    else:
        clog.setLevel(logging.DEBUG)

    return clog 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:27,代码来源:main.py

示例5: get_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
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 
开发者ID:koenvervloesem,项目名称:hermes-audio-server,代码行数:24,代码来源:logger.py

示例6: init_loggers

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def init_loggers():
  """
  Function initialize loggers
  """
  formatter = ColoredFormatter("%(log_color)s%(levelname)-8s%(reset)s %(white)s%(message)s",
                               datefmt=None,
                               reset=True,
                               log_colors={
                                   'DEBUG':    'cyan',
                                   'INFO':     'white',
                                   'WARNING':  'yellow',
                                   'ERROR':    'red',
                                   'CRITICAL': 'red,bg_white',
                               },
                               secondary_log_colors={},
                               style='%'
                              )

  handler = logging.StreamHandler()
  handler.setFormatter(formatter)

  ROOTLOGGER.addHandler(handler) 
开发者ID:aacebedo,项目名称:i3-xfce,代码行数:24,代码来源:loggers.py

示例7: init

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def init(loop, argv):
    parser = argparse.ArgumentParser(description="Test node connector ...")
    args = parser.parse_args()
    config_file = "test.conf"
    log_level = logging.INFO
    logger = colorlog.getLogger('cn')
    config = configparser.ConfigParser()
    config.read(config_file)

    ch = logging.StreamHandler()
    ch.setLevel(log_level)
    formatter = colorlog.ColoredFormatter('%(log_color)s%(asctime)s %(levelname)s: %(message)s (%(module)s:%(lineno)d)')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    logger.setLevel(log_level)
    logger.info("Start")
    loop = asyncio.get_event_loop()
    app = App(loop, logger, config)
    return app 
开发者ID:bitaps-com,项目名称:pybtc,代码行数:21,代码来源:test.py

示例8: init_logging

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def init_logging():
    log = logging.getLogger('CL')
    term_handler = logging.StreamHandler()

    try:
        import colorlog
        fmt = colorlog.ColoredFormatter('%(asctime)s %(log_color)s[%(name)12s:%(lineno)3s'
                                        ' %(funcName)18s ]\t%(levelname)-.6s  %(message)s')
    except ImportError:
        fmt = logging.Formatter('%(asctime)s [%(name)12s:%(lineno)3s '
                                '%(funcName)18s ]\t%(levelname)-.6s  %(message)s')

    term_handler.setFormatter(fmt)
    log.addHandler(term_handler)
    log.setLevel(logging.DEBUG)
    return log 
开发者ID:busimus,项目名称:cutelog,代码行数:18,代码来源:config.py

示例9: get

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def get(cls, tag):
        """
        Get the global logger instance for the given tag

        :param tag: the log tag
        :return: the logger instance
        """
        if tag not in cls._LOGGERS:
            if cls._use_color:
                handler = colorlog.StreamHandler()
                handler.setFormatter(colorlog.ColoredFormatter( \
                    ' %(log_color)s%(name)s/%(levelname)-8s%(reset)s |'
                    ' %(log_color)s%(message)s%(reset)s'))
            else:
                handler = logging.StreamHandler()
                handler.setFormatter(logging.Formatter( \
                    ' %(name)s/%(levelname)-8s | %(message)s'))

            logger = logging.getLogger(tag)
            logger.addHandler(handler)

            cls._LOGGERS[tag] = logger

        return cls._LOGGERS[tag] 
开发者ID:cyanogen,项目名称:uchroma,代码行数:26,代码来源:log.py

示例10: setup_logging

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def setup_logging():
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    color_formatter = ColoredFormatter(
	        "%(log_color)s[%(asctime)s] [%(levelname)-4s]%(reset)s - %(message)s",
	        datefmt='%d-%m-%y %H:%M:%S',
	        reset=True,
	        log_colors={
		        'DEBUG':    'cyan',
		        'INFO':     'green',
		        'WARNING':  'bold_yellow',
		        'ERROR':    'bold_red',
		        'CRITICAL': 'bold_red',
	        },
	        secondary_log_colors={},
	        style='%')
    logging_handler = logging.StreamHandler()
    logging_handler.setFormatter(color_formatter)
    logger.addHandler(logging_handler)

# setup logging for script 
开发者ID:Mind0xP,项目名称:Frida-Python-Binding,代码行数:23,代码来源:fridaPyBinding.py

示例11: setup_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def setup_logger(name, level, colors=COLORS,
                 format_string="%(purple)s%(name)s> %(log_color)s%(message)s"):
    """Set up a particular logger with overridden behavior.

    Args:
        name (str): The name of the logger.
        level (int): The log level to set this logger to.
        colors (dict): A dictionary of log colors.
        format_string (str): The format of the log message.
    """
    logger_ = logging.getLogger(name)
    logger_.setLevel(level)
    formatter = ColoredFormatter(format_string, reset=True, log_colors=colors)
    if logger_.handlers:
        logger_.handlers.pop()
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger_.addHandler(handler)
    logger_.propagate = False
    return logger_


# Make the logger and output_logger available for import from elsewhere. 
开发者ID:googleapis,项目名称:artman,代码行数:25,代码来源:logger.py

示例12: configure_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def configure_logger():
    """
        This function is responsible to configure logging object.
    """

    global LOGGER
    LOGGER = logging.getLogger("Autobrowser")
    # Set logging level
    LOGGER.setLevel(logging.DEBUG)

    # Create console handler
    log_colors = {
        'DEBUG': 'bold_blue',
        'INFO': 'green',
        'WARNING': 'purple',
        'ERROR': 'red',
        'CRITICAL': 'bold_yellow',
    }
    formatter = "%(log_color)s[%(asctime)s] - %(message)s%(reset)s"
    formatter = ColoredFormatter(formatter, datefmt='%d-%m-%Y %H:%M', log_colors=log_colors)
    ch = logging.StreamHandler(sys.stdout)
    ch.setFormatter(formatter)
    LOGGER.addHandler(ch) 
开发者ID:El3ct71k,项目名称:AutoBrowser,代码行数:25,代码来源:AutoBrowser.py

示例13: getLogFormat

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def getLogFormat(self, type):
        if type == 'stdout':
            format = global_config.LOG_STDOUT_FORMAT
        elif type == 'file':
            format = global_config.LOG_FILE_FORMAT

        if format == "json":
            return CustomJsonFormatter(
                '%(time) %(level) %(component) %(module)%(message) %(pathname)'
                ' %(lineno)%(processName) %(threadName)%(node)')
        else:
            return ColoredFormatter(
                '%(log_color)s[%(asctime)s] %(levelname)-10s: '
                '%(name)s.%(module)-10s -%(message)s '
                '[in %(pathname)s:%(lineno)d]%(reset)s'
            ) 
开发者ID:mundialis,项目名称:actinia_core,代码行数:18,代码来源:logging_interface.py

示例14: setup_logging

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def setup_logging():  # pragma: no cover
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.INFO)
    handler = logging.StreamHandler()

    formatter = ColoredFormatter(
        "%(log_color)s%(levelname)-8s%(reset)s %(asctime)s %(green)s%(name)s"
        "%(reset)s %(message)s",
        reset=True,
        log_colors={
            'DEBUG':    'cyan',
            'INFO':     'blue',
            'WARNING':  'yellow',
            'ERROR':    'red',
            'CRITICAL': 'red,bg_white',
        }
    )

    handler.setFormatter(formatter)
    root_logger.addHandler(handler) 
开发者ID:GoogleCloudPlatform,项目名称:psq,代码行数:22,代码来源:psqworker.py

示例15: __init__

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import ColoredFormatter [as 别名]
def __init__(self, lvl=logging.DEBUG, format=None):
        self._lvl = lvl
        if not format:
            format = "  %(log_color)s%(styledname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s"
        self.format = format
        logging.root.setLevel(self._lvl)
        self.formatter = colorlog.ColoredFormatter(self.format)
        self.stream = logging.StreamHandler()
        self.stream.setLevel(self._lvl)
        self.stream.setFormatter(self.formatter)
        self.logger = logging.getLogger('pythonConfig')
        self.logger.setLevel(self._lvl)
        self.logger.addHandler(self.stream)
        self.theme = THEME
        self.extra = {"styledname": self.theme[self._lvl]}

    # the magic happens here: we use the "extra" argument documented in
    # https://docs.python.org/2/library/logging.html#logging.Logger.debug
    # to inject new items into the logging.LogRecord objects
    # we also create our convenience methods here 
开发者ID:ManufacturaInd,项目名称:python-zenlog,代码行数:22,代码来源:__init__.py


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