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


Python logger.ILogObserver方法代码示例

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


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

示例1: test_loggerComponentBeatsLegacyLoggerComponent

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def test_loggerComponentBeatsLegacyLoggerComponent(self):
        """
        A L{ILogObserver} takes precedence over a L{LegacyILogObserver}
        component set on Application.
        """
        nonlogs = []
        observer = self._makeObserver()
        application = Componentized()
        application.setComponent(ILogObserver, observer)
        application.setComponent(LegacyILogObserver, nonlogs.append)

        logger = app.AppLogger({})
        logger.start(application)

        self._checkObserver(observer)
        self.assertEqual(nonlogs, []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_twistd.py

示例2: test_unmarkedObserversDeprecated

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def test_unmarkedObserversDeprecated(self):
        """
        L{app.AppLogger} using a logger observer which does not implement
        L{ILogObserver} or L{LegacyILogObserver} will be wrapped in a compat
        shim and raise a L{DeprecationWarning}.
        """
        logs = []
        logger = app.AppLogger({})
        logger._getLogObserver = lambda: logs.append
        logger.start(Componentized())

        self.assertIn("starting up", textFromEventDict(logs[0]))

        warnings = self.flushWarnings(
            [self.test_unmarkedObserversDeprecated])
        self.assertEqual(len(warnings), 1)
        self.assertEqual(warnings[0]["message"],
                         ("Passing a logger factory which makes log observers "
                          "which do not implement twisted.logger.ILogObserver "
                          "or twisted.python.log.ILogObserver to "
                          "twisted.application.app.AppLogger was deprecated "
                          "in Twisted 16.2. Please use a factory that "
                          "produces twisted.logger.ILogObserver (or the "
                          "legacy twisted.python.log.ILogObserver) "
                          "implementing objects instead.")) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:27,代码来源:test_twistd.py

示例3: _makeObserver

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def _makeObserver(self):
        """
        Make a new observer which captures all logs sent to it.

        @return: An observer that stores all logs sent to it.
        @rtype: Callable that implements L{ILogObserver}.
        """
        @implementer(ILogObserver)
        class TestObserver(object):
            _logs = []

            def __call__(self, event):
                self._logs.append(event)

        return TestObserver() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_twistd.py

示例4: test_startUsesApplicationLogObserver

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def test_startUsesApplicationLogObserver(self):
        """
        When the L{ILogObserver} component is available on the application,
        that object will be used as the log observer instead of constructing a
        new one.
        """
        application = Componentized()
        observer = self._makeObserver()
        application.setComponent(ILogObserver, observer)
        logger = app.AppLogger({})
        logger.start(application)
        self._checkObserver(observer) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_twistd.py

示例5: test_configuredLogObserverBeatsComponent

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def test_configuredLogObserverBeatsComponent(self):
        """
        C{--logger} takes precedence over a L{ILogObserver} component set on
        Application.
        """
        observer = self._makeObserver()
        application = Componentized()
        application.setComponent(ILogObserver, observer)
        self._checkObserver(self._setupConfiguredLogger(application))
        self.assertEqual(observer._logs, []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_twistd.py

示例6: __call__

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def __call__(self, event):
        """
        @see: L{ILogObserver}
        """
        self._events.append(event) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:7,代码来源:testing.py

示例7: test_resolveNameFailure

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def test_resolveNameFailure(self):
        """
        A resolution failure is logged with the name that failed to
        resolve and the callable that tried to resolve it.  The
        resolution receiver begins, receives no addresses, and
        completes.
        """
        logs = []

        @provider(ILogObserver)
        def captureLogs(event):
            logs.append(event)

        globalLogPublisher.addObserver(captureLogs)
        self.addCleanup(lambda: globalLogPublisher.removeObserver(captureLogs))

        receiver = self.resolver.resolveHostName(self.receiver, "example.com")

        self.assertIs(receiver, self.receiver)

        self.fakeResolverReturns.errback(Exception())

        self.assertEqual(1, len(logs))
        self.assertEqual(1, len(self.flushLoggedErrors(Exception)))

        [event] = logs
        self.assertTrue(event.get("isError"))
        self.assertTrue(event.get("name", "example.com"))
        self.assertTrue(event.get("callable", repr(self.fakeResolver)))

        self.assertEqual(1, len(self.resolutionBeganCalls))
        self.assertEqual(self.resolutionBeganCalls[0].name, "example.com")
        self.assertFalse(self.addressResolvedCalls)
        self.assertEqual(1, self.resolutionCompleteCallCount) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:36,代码来源:test_endpoints.py

示例8: start

# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def start(self, application):
        """
        Initialize the global logging system for the given application.

        If a custom logger was specified on the command line it will be used.
        If not, and an L{logger.ILogObserver} or legacy L{log.ILogObserver}
        component has been set on C{application}, then it will be used as the
        log observer. Otherwise a log observer will be created based on the
        command line options for built-in loggers (e.g. C{--logfile}).

        @param application: The application on which to check for an
            L{logger.ILogObserver} or legacy L{log.ILogObserver}.
        @type application: L{twisted.python.components.Componentized}
        """
        if self._observerFactory is not None:
            observer = self._observerFactory()
        else:
            observer = application.getComponent(logger.ILogObserver, None)
            if observer is None:
                # If there's no new ILogObserver, try the legacy one
                observer = application.getComponent(log.ILogObserver, None)

        if observer is None:
            observer = self._getLogObserver()
        self._observer = observer

        if logger.ILogObserver.providedBy(self._observer):
            observers = [self._observer]
        elif log.ILogObserver.providedBy(self._observer):
            observers = [logger.LegacyLogObserverWrapper(self._observer)]
        else:
            warnings.warn(
                ("Passing a logger factory which makes log observers which do "
                 "not implement twisted.logger.ILogObserver or "
                 "twisted.python.log.ILogObserver to "
                 "twisted.application.app.AppLogger was deprecated in "
                 "Twisted 16.2. Please use a factory that produces "
                 "twisted.logger.ILogObserver (or the legacy "
                 "twisted.python.log.ILogObserver) implementing objects "
                 "instead."),
                DeprecationWarning,
                stacklevel=2)
            observers = [logger.LegacyLogObserverWrapper(self._observer)]

        logger.globalLogBeginner.beginLoggingTo(observers)
        self._initialLog() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:48,代码来源:app.py


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