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


Python colorlog.getLogger方法代码示例

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


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

示例1: get_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [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

示例2: init

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [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

示例3: create_default_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def create_default_logger(level=logging.DEBUG,
                          fname='/tmp/ethereumd-proxy.log'):
    handler = logging.FileHandler(fname)
    formatter = colorlog.ColoredFormatter(
        "%(log_color)s[%(asctime)s %(levelname)s "
        "%(name)s - %(module)s:%(funcName)s:%(lineno)d]"
        "%(reset)s %(blue)s%(message)s",
        datefmt=None,
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red,bg_white',
        },
        secondary_log_colors={},
        style='%'
    )
    handler.setFormatter(formatter)
    handler.setLevel(level)
    logger = colorlog.getLogger()
    logger.addHandler(handler)
    logger.setLevel(level)
    return logger 
开发者ID:DeV1doR,项目名称:ethereumd-proxy,代码行数:27,代码来源:utils.py

示例4: setup_logging

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def setup_logging(log_level_str: str = 'info') -> None:
    EVENT_LOG_LEVEL = 25
    logging.addLevelName(EVENT_LOG_LEVEL, 'EVENT')

    def event(self, message, *args, **kwargs):
        if self.isEnabledFor(EVENT_LOG_LEVEL):
            self._log(EVENT_LOG_LEVEL, message, args, **kwargs)
    # we're adding a new function to Logger so ignore the type here to make mypy happy
    logging.Logger.event = event  # type: ignore

    handler = colorlog.StreamHandler()
    handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(levelname)s:%(name)s:%(message)s'))
    logger = colorlog.getLogger()
    logger.addHandler(handler)

    log_level = getattr(logging, log_level_str.upper())
    logging.getLogger().setLevel(log_level)
    logging.getLogger('botocore').setLevel(max(logging.INFO, log_level))
    logging.getLogger('boto3').setLevel(max(logging.INFO, log_level)) 
开发者ID:Yelp,项目名称:clusterman,代码行数:21,代码来源:util.py

示例5: set_colored_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def set_colored_logger(name, level='INFO'):
    logger = colorlog.getLogger(name)
    logging_level = logging.getLevelName(level)
    logger.setLevel(logging_level)
    _add_handler(logger, _color_handler)
    # print("now handlers: {}".format(logger.handlers))
    return logger 
开发者ID:mileyan,项目名称:DARENet,代码行数:9,代码来源:logging.py

示例6: get_colored_logger

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def get_colored_logger(name):
    return colorlog.getLogger(name) 
开发者ID:mileyan,项目名称:DARENet,代码行数:4,代码来源:logging.py

示例7: test_colorlog_basicConfig

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def test_colorlog_basicConfig(test_logger):
    colorlog.basicConfig()
    test_logger(colorlog.getLogger()) 
开发者ID:aeroxis,项目名称:sultan,代码行数:5,代码来源:test_logging.py

示例8: test_example

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def test_example():
    """Tests the usage example from the README"""
    import colorlog

    handler = colorlog.StreamHandler()
    handler.setFormatter(colorlog.ColoredFormatter(
        '%(log_color)s%(levelname)s:%(name)s:%(message)s'))
    logger = colorlog.getLogger('example')
    logger.addHandler(handler) 
开发者ID:aeroxis,项目名称:sultan,代码行数:11,代码来源:test_example.py

示例9: __init__

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def __init__(self, path: str, recursive=False, worker_count=cpu_count() * 2, verbose=0) -> None:
        """
        Create an OCyara object that can scan the specified directory or file and store the results.

        Arguments:
            path -- File or directory to be processed

        Keyword Arguments:
            recursive -- Whether the specified path should be recursivly searched for images (default False)
            worker_count -- The number of worker processes that should be spawned when
                            run() is executed (default available CPU cores * 2)
            verbose -- An int() from 0-2 that sets the verbosity level.
                       0 is default, 1 is information and 2 is debug
        """
        self.path = path
        self.recursive = recursive
        self.q = JoinableQueue()
        self.results = {}
        self.threads = worker_count
        self.lock = Lock()
        self.workers = []
        if os.path.isdir(self.path):
            if self.path[-1] is '/':
                self.path += '*'
            else:
                self.path += '/*'
        self.manager = Manager()
        self.matchedfiles = None
        self.total_items_to_queue = None
        self.total_added_to_queue = None
        self.queue_items_completed = None
        self.tempdir = tempfile.TemporaryDirectory()
        handler = colorlog.StreamHandler()
        handler.setFormatter(colorlog.ColoredFormatter(
                '%(log_color)s%(levelname)s:%(name)s:%(message)s'))
        self.logger = colorlog.getLogger('OCyara')
        self.logger.addHandler(handler)
        if verbose == 1:
            self.logger.setLevel('INFO')
        elif verbose > 1:
            self.logger.setLevel('DEBUG')
        else:
            self.logger.setLevel('WARN') 
开发者ID:bandrel,项目名称:OCyara,代码行数:45,代码来源:ocyara.py

示例10: _process_image

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def _process_image(self, yara_rule: str, save_context: bool) -> None:
        """
        Perform OCR and yara rule matching as a worker.

        process_image() is used by the run() method to create multiple worker processes for
        parallel execution.  process_image normally will not be called directly.

        Arguments:
            yara_rule -- File path pointing to a Yara rule file
        """
        context = None
        handler = colorlog.StreamHandler()
        handler.setFormatter(colorlog.ColoredFormatter(
                '%(log_color)s%(levelname)s:%(name)s:%(message)s'))
        # Creates a logger object for the individual workers that contains the PID as part of the message header
        worker_logger = colorlog.getLogger('worker_'+str(os.getpid()))
        worker_logger.addHandler(handler)
        worker_logger.setLevel(self.logger.level)
        worker_logger.info('PID {0} created to process queue'.format(str(os.getpid())))
        while True:
            try:
                image, filepath = self.q.get(timeout=.25)
            except Empty:
                if self.total_added_to_queue[0] == self.total_items_to_queue[0]:
                    worker_logger.debug('Queue Empty PID %d exiting' % os.getpid())
                    return
                else:
                    worker_logger.debug('Queue still loading')
                    continue
            ocrtext = tesserocr.image_to_text(image)
            try:
                rules = yara.compile(yara_rule)
            except yara.Error:
                worker_logger.error('Invalid rule file/rule file not found: {0}'.format(yara_rule))
            matches = rules.match(data=ocrtext)
            # If there is a match, store the filename and the rule in a dictionary local to this process.
            # Create an editable copy of the master manager dict.
            with self.lock:
                local_results_dict = self.matchedfiles[0]
                if matches:
                    if save_context:
                        context = ocrtext
                    for x in matches:
                        try:
                            local_results_dict[filepath].append((x.rule, context))
                        except KeyError:
                            local_results_dict[filepath] = [(x.rule, context)]
                    self.matchedfiles[0] = local_results_dict
            self.queue_items_completed[0] += 1
            self.q.task_done() 
开发者ID:bandrel,项目名称:OCyara,代码行数:52,代码来源:ocyara.py

示例11: initialize_logging

# 需要导入模块: import colorlog [as 别名]
# 或者: from colorlog import getLogger [as 别名]
def initialize_logging(prefix: str, logging_config: Dict, root_path: Path):
    log_path = path_from_root(
        root_path, logging_config.get("log_filename", "log/debug.log")
    )
    mkdir(str(log_path.parent))
    if logging_config["log_stdout"]:
        handler = colorlog.StreamHandler()
        handler.setFormatter(
            colorlog.ColoredFormatter(
                f"{prefix}: %(log_color)s%(levelname)-8s%(reset)s %(asctime)s.%(msecs)03d %(message)s",
                datefmt="%H:%M:%S",
                reset=True,
            )
        )

        logger = colorlog.getLogger()
        logger.addHandler(handler)
    else:
        logging.basicConfig(
            filename=log_path,
            filemode="a",
            format=f"{prefix}: %(levelname)-8s %(asctime)s.%(msecs)03d %(message)s",
            datefmt="%H:%M:%S",
        )

        logger = logging.getLogger()
        handler = RotatingFileHandler(log_path, maxBytes=20000000, backupCount=7)
        logger.addHandler(handler)

    if "log_level" in logging_config:
        if logging_config["log_level"] == "CRITICAL":
            logger.setLevel(logging.CRITICAL)
        elif logging_config["log_level"] == "ERROR":
            logger.setLevel(logging.ERROR)
        elif logging_config["log_level"] == "WARNING":
            logger.setLevel(logging.WARNING)
        elif logging_config["log_level"] == "INFO":
            logger.setLevel(logging.INFO)
        elif logging_config["log_level"] == "DEBUG":
            logger.setLevel(logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.INFO) 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:46,代码来源:logging.py


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