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


Python logging.Filter方法代码示例

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


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

示例1: setup_stream_handlers

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def setup_stream_handlers(conf):
    """Setup logging stream handlers according to the options."""
    class StdoutFilter(logging.Filter):
        def filter(self, record):
            return record.levelno in (logging.DEBUG, logging.INFO)

    log.handlers = []

    stdout_handler = logging.StreamHandler(sys.stdout)
    stdout_handler.setLevel(logging.WARNING)
    stdout_handler.addFilter(StdoutFilter())
    if conf.debug:
        stdout_handler.setLevel(logging.DEBUG)
    elif conf.verbose:
        stdout_handler.setLevel(logging.INFO)
    else:
        stdout_handler.setLevel(logging.WARNING)
    log.addHandler(stdout_handler)

    stderr_handler = logging.StreamHandler(sys.stderr)
    msg_format = "%(levelname)s: %(message)s"
    stderr_handler.setFormatter(logging.Formatter(fmt=msg_format))
    stderr_handler.setLevel(logging.WARNING)
    log.addHandler(stderr_handler) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:26,代码来源:cli.py

示例2: test_logging_filters

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def test_logging_filters(sentry_init, capture_events):
    sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
    events = capture_events()

    should_log = False

    class MyFilter(logging.Filter):
        def filter(self, record):
            return should_log

    logger.addFilter(MyFilter())
    logger.error("hi")

    assert not events

    should_log = True
    logger.error("hi")

    (event,) = events
    assert event["logentry"]["message"] == "hi" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:22,代码来源:test_logging.py

示例3: setup_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def setup_logging(verbose=0, colors=False, name=None):
    """Configure console logging. Info and below go to stdout, others go to stderr.

    :param int verbose: Verbosity level. > 0 print debug statements. > 1 passed to sphinx-build.
    :param bool colors: Print color text in non-verbose mode.
    :param str name: Which logger name to set handlers to. Used for testing.
    """
    root_logger = logging.getLogger(name)
    root_logger.setLevel(logging.DEBUG if verbose > 0 else logging.INFO)
    formatter = ColorFormatter(verbose > 0, colors)
    if colors:
        colorclass.Windows.enable()

    handler_stdout = logging.StreamHandler(sys.stdout)
    handler_stdout.setFormatter(formatter)
    handler_stdout.setLevel(logging.DEBUG)
    handler_stdout.addFilter(type('', (logging.Filter,), {'filter': staticmethod(lambda r: r.levelno <= logging.INFO)}))
    root_logger.addHandler(handler_stdout)

    handler_stderr = logging.StreamHandler(sys.stderr)
    handler_stderr.setFormatter(formatter)
    handler_stderr.setLevel(logging.WARNING)
    root_logger.addHandler(handler_stderr) 
开发者ID:sphinx-contrib,项目名称:sphinxcontrib-versioning,代码行数:25,代码来源:setup_logging.py

示例4: configure_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def configure_logging(app: "sphinx.application.Sphinx") -> None:
    """Configure Sphinx's WarningHandler to handle (expected) missing include."""
    import sphinx.util.logging
    import logging

    class WarnLogFilter(logging.Filter):
        def filter(self, record: logging.LogRecord) -> bool:
            """Ignore warnings about missing include with "only" directive.

            Ref: https://github.com/sphinx-doc/sphinx/issues/2150."""
            if (
                record.msg.startswith('Problems with "include" directive path:')
                and "_changelog_towncrier_draft.rst" in record.msg
            ):
                return False
            return True

    logger = logging.getLogger(sphinx.util.logging.NAMESPACE)
    warn_handler = [x for x in logger.handlers if x.level == logging.WARNING]
    assert len(warn_handler) == 1, warn_handler
    warn_handler[0].filters.insert(0, WarnLogFilter()) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:23,代码来源:conf.py

示例5: test_filter

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def test_filter(self):
        # Only messages satisfying the specified criteria pass through the
        #  filter.
        filter_ = logging.Filter("spam.eggs")
        handler = self.root_logger.handlers[0]
        try:
            handler.addFilter(filter_)
            spam = logging.getLogger("spam")
            spam_eggs = logging.getLogger("spam.eggs")
            spam_eggs_fish = logging.getLogger("spam.eggs.fish")
            spam_bakedbeans = logging.getLogger("spam.bakedbeans")

            spam.info(self.next_message())
            spam_eggs.info(self.next_message())  # Good.
            spam_eggs_fish.info(self.next_message())  # Good.
            spam_bakedbeans.info(self.next_message())

            self.assert_log_lines([
                ('spam.eggs', 'INFO', '2'),
                ('spam.eggs.fish', 'INFO', '3'),
            ])
        finally:
            handler.removeFilter(filter_) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_logging.py

示例6: _resize_selection_box

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def _resize_selection_box(self, new_box):
        import inspect # Let's get our hands dirty
        stack = inspect.stack()
        filename = os.path.basename(stack[1][1])
        old_box = self.selectionTool.selectionBox()
        msg = """
        Filter "{0}" wants to resize the selection box
        Origin: {1} -> {2}
        Size: {3} -> {4}
        Do you want to resize the Selection Box?""".format(
                   filename, 
                   (old_box.origin[0], old_box.origin[1], old_box.origin[2]), 
                   (new_box.origin[0], new_box.origin[1], new_box.origin[2]), 
                   (old_box.size[0], old_box.size[1], old_box.size[2]), 
                   (new_box.size[0], new_box.size[1], new_box.size[2])
                   )
        result = ask(msg, ["Yes", "No"])
        if result == "Yes":
            self.selectionTool.setSelection(new_box)
            return new_box
        else:
            return False 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:24,代码来源:leveleditor.py

示例7: configure_filter

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def configure_filter(self, config):
        """Configure a filter from a dictionary."""
        if '()' in config:
            result = self.configure_custom(config)
        else:
            name = config.get('name', '')
            result = logging.Filter(name)
        return result 
开发者ID:war-and-code,项目名称:jawfish,代码行数:10,代码来源:config.py

示例8: __init__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def __init__(self, *args, **kwargs):
        # Can't use super() because logging.Filter is an old-style class in py26
        logging.Filter.__init__(self, *args, **kwargs)
        self.warning_count = self.error_count = 0 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:runtests.py

示例9: _new_custom_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def _new_custom_logger(name='BiblioPixel',
                       fmt='%(levelname)s - %(module)s - %(message)s'):
    logger = logging.getLogger(name)
    formatter = logging.Formatter(fmt=fmt)

    def add_handler(level, outfile):
        class Filter(logging.Filter):
            def filter(self, rec):
                return rec.levelno == level

        h = logging.StreamHandler(outfile)
        h.setLevel(level)
        h.addFilter(Filter())
        h.setFormatter(formatter)
        logger.addHandler(h)

    if not logger.handlers:
        logger.setLevel(INFO)
        add_handler(FRAME, sys.stdout)
        add_handler(DEBUG, sys.stdout)
        add_handler(INFO, sys.stdout)
        add_handler(WARNING, sys.stderr)
        add_handler(ERROR, sys.stderr)

    else:  # pragma: no cover
        pass

    return logger 
开发者ID:ManiacalLabs,项目名称:BiblioPixel,代码行数:30,代码来源:log.py

示例10: __init__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def __init__(self):
            logging.Filter.__init__(self)
            self.modulesLevel = {} 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:5,代码来源:rmLogging.py

示例11: test_filter

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def test_filter(self):
        # Only messages satisfying the specified criteria pass through the
        #  filter.
        filter_ = logging.Filter("spam.eggs")
        handler = self.root_logger.handlers[0]
        try:
            handler.addFilter(filter_)
            spam = logging.getLogger("spam")
            spam_eggs = logging.getLogger("spam.eggs")
            spam_eggs_fish = logging.getLogger("spam.eggs.fish")
            spam_bakedbeans = logging.getLogger("spam.bakedbeans")

            spam.info(self.next_message())
            spam_eggs.info(self.next_message())  # Good.
            spam_eggs_fish.info(self.next_message())  # Good.
            spam_bakedbeans.info(self.next_message())

            self.assert_log_lines([
                ('spam.eggs', 'INFO', '2'),
                ('spam.eggs.fish', 'INFO', '3'),
            ])
        finally:
            handler.removeFilter(filter_)


#
#   First, we define our levels. There can be as many as you want - the only
#     limitations are that they should be integers, the lowest should be > 0 and
#   larger values mean less information being logged. If you need specific
#   level values which do not fit into these limitations, you can use a
#   mapping dictionary to convert between your application levels and the
#   logging system.
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:test_logging.py

示例12: test_logger_filter

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def test_logger_filter(self):
        # Filter at logger level.
        self.root_logger.setLevel(VERBOSE)
        # Levels >= 'Verbose' are good.
        self.log_at_all_levels(self.root_logger)
        self.assert_log_lines([
            ('Verbose', '5'),
            ('Sociable', '6'),
            ('Effusive', '7'),
            ('Terse', '8'),
            ('Taciturn', '9'),
            ('Silent', '10'),
        ]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_logging.py

示例13: test_handler_filter

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def test_handler_filter(self):
        # Filter at handler level.
        self.root_logger.handlers[0].setLevel(SOCIABLE)
        try:
            # Levels >= 'Sociable' are good.
            self.log_at_all_levels(self.root_logger)
            self.assert_log_lines([
                ('Sociable', '6'),
                ('Effusive', '7'),
                ('Terse', '8'),
                ('Taciturn', '9'),
                ('Silent', '10'),
            ])
        finally:
            self.root_logger.handlers[0].setLevel(logging.NOTSET) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_logging.py

示例14: __init__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def __init__(self, *errorfilter):
        self.errorfilter = [logging.Filter(name) for name in errorfilter] 
开发者ID:piejanssens,项目名称:premiumizer,代码行数:4,代码来源:premiumizer.py

示例15: __init__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import Filter [as 别名]
def __init__(self):
        logging.Filter.__init__(self)
        self.warning_table = {} 
开发者ID:medbenali,项目名称:CyberScan,代码行数:5,代码来源:error.py


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