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


Python MementoHandler.addFilter方法代码示例

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


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

示例1: FilterTests

# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import addFilter [as 别名]
class FilterTests(unittest.TestCase):
    """Tests log filters"""

    @defer.inlineCallbacks
    def setUp(self):
        """Setup the logger and the handler"""
        yield super(FilterTests, self).setUp()
        self.handler = MementoHandler()
        self.handler.setLevel(logging.DEBUG)
        root_logger.addHandler(self.handler)
        self.addCleanup(root_logger.removeHandler, self.handler)

        if filesystem_logger is not None:
            filesystem_logger.addHandler(self.handler)
            self.addCleanup(filesystem_logger.removeHandler, self.handler)

        twisted_logger.addHandler(self.handler)
        self.addCleanup(twisted_logger.removeHandler, self.handler)

        self.addCleanup(self.handler.close)

    @skipIfOS('win32', 'There is not filesystem_logger implementation in '\
                       'windows yet, see bug #823316.')
    def test_multiple_filters(self):
        """Tests logging with more than one filter."""
        test_logger = logging.getLogger('ubuntuone.SyncDaemon.FilterTest')
        test_logger.debug('debug info 0')
        self.assertEquals(1, len(self.handler.records))
        self.handler.addFilter(MultiFilter(['ubuntuone.SyncDaemon', 'twisted', 'pyinotify']))
        test_logger.debug('debug info 1')
        self.assertEquals(2, len(self.handler.records))
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:33,代码来源:test_logger.py

示例2: MultiFilterTest

# 需要导入模块: from ubuntuone.devtools.handlers import MementoHandler [as 别名]
# 或者: from ubuntuone.devtools.handlers.MementoHandler import addFilter [as 别名]
class MultiFilterTest(unittest.TestCase):
    """Tests for logger.MultiFilter"""

    @defer.inlineCallbacks
    def setUp(self):
        """Setup the logger and the handler"""
        yield super(MultiFilterTest, self).setUp()
        self.handler = MementoHandler()
        self.logger = logging.getLogger(self.__class__.__name__)
        self.logger.addHandler(self.handler)
        self.logger.setLevel(logging.DEBUG)

    @defer.inlineCallbacks
    def tearDown(self):
        """close the handler and restore the logger (Logger's are global)"""
        yield super(MultiFilterTest, self).tearDown()
        self.handler.close()
        self.logger.removeHandler(self.handler)
        self.logger.setLevel(logging.DEBUG)

    def test_no_filters(self):
        """Tests filtering without any filter in self.filters."""
        self.handler.addFilter(MultiFilter())
        self.logger.debug('this msg should be logged')
        self.assertEqual(1, len(self.handler.records))

    def test_single_filter(self):
        """Tests filtering with one filter."""
        self.handler.addFilter(MultiFilter([self.__class__.__name__]))
        self.logger.debug('this msg should be logged')
        self.assertEqual(1, len(self.handler.records))
        other_logger = logging.getLogger("NO_LOG."+self.__class__.__name__)
        other_logger.debug('this msg shouldn\'t be logged')
        self.assertEqual(1, len(self.handler.records))

    def test_multiple_filters(self):
        """Tests filtering with more than one filter."""
        self.handler.addFilter(
            MultiFilter([self.__class__.__name__,
                         self.__class__.__name__ + ".child"]))
        no_logger = logging.getLogger("NO_LOG."+self.__class__.__name__)
        yes_logger = logging.getLogger(self.__class__.__name__ + '.child')
        self.logger.debug('this msg should be logged')
        self.assertEqual(1, len(self.handler.records))
        no_logger.debug('this msg shouldn\'t be logged')
        self.assertEqual(1, len(self.handler.records))
        yes_logger.debug('this msg from a child logger should be logged')
        self.assertEqual(2, len(self.handler.records))
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:50,代码来源:test_logger.py


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