本文整理汇总了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, [])
示例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."))
示例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()
示例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)
示例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, [])
示例6: __call__
# 需要导入模块: from twisted import logger [as 别名]
# 或者: from twisted.logger import ILogObserver [as 别名]
def __call__(self, event):
"""
@see: L{ILogObserver}
"""
self._events.append(event)
示例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)
示例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()