本文整理汇总了Python中twisted.python.log.ILogObserver方法的典型用法代码示例。如果您正苦于以下问题:Python log.ILogObserver方法的具体用法?Python log.ILogObserver怎么用?Python log.ILogObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.log
的用法示例。
在下文中一共展示了log.ILogObserver方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setServiceParent
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import ILogObserver [as 别名]
def setServiceParent(self, app):
MultiService.setServiceParent(self, app)
if self.logEnabled:
errorLogFile = LogFile.fromFullPath(
self.logPath,
rotateLength=self.logRotateLength,
maxRotatedFiles=self.logMaxFiles
)
if self.logRotateOnStart:
errorLogFile.rotate()
encoding = "utf-8"
else:
errorLogFile = sys.stdout
encoding = sys.stdout.encoding
withTime = not (not config.ErrorLogFile and config.ProcessType in ("Slave", "DPS",))
errorLogObserver = Logger.makeFilteredFileLogObserver(errorLogFile, withTime=withTime)
# We need to do this because the current Twisted logger implementation fails to setup the encoding
# correctly when a L{twisted.python.logile.LogFile} is passed to a {twisted.logger._file.FileLogObserver}
errorLogObserver._observers[0]._encoding = encoding
# Registering ILogObserver with the Application object
# gets our observer picked up within AppLogger.start( )
app.setComponent(ILogObserver, errorLogObserver)
示例2: test_nonAsciiLog
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import ILogObserver [as 别名]
def test_nonAsciiLog(self):
"""
Make sure that the file based error log can write non ascii data
"""
logpath = self.mktemp()
service = ErrorLoggingMultiService(
True,
logpath,
10000,
10,
False,
)
app = Application("non-ascii")
service.setServiceParent(app)
observer = app.getComponent(ILogObserver, None)
self.assertTrue(observer is not None)
log = Logger(observer=observer)
log.error(u"Couldn\u2019t be wrong")
with open(logpath) as f:
logentry = f.read()
self.assertIn("Couldn\xe2\x80\x99t be wrong", logentry)
示例3: start
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import ILogObserver [as 别名]
def start(self, application):
"""
Initialize the logging system.
If an L{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.
@param application: The application on which to check for an
L{ILogObserver}.
"""
observer = application.getComponent(ILogObserver, None)
if observer is None:
observer = self._getLogObserver()
self._observer = observer
log.startLoggingWithObserver(self._observer)
self._initialLog()
示例4: CanvasApp
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import ILogObserver [as 别名]
def CanvasApp(nginx=False):
application = service.Application("Canvas")
web_server = CanvasTCPServer()
web_server.setServiceParent(application)
log_file = logfile.LogFile(
name="twistd.log",
directory="/var/canvas/website/run",
maxRotatedFiles=100,
)
application.setComponent(log.ILogObserver, log.FileLogObserver(log_file).emit)
return application
示例5: setServiceParent
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import ILogObserver [as 别名]
def setServiceParent(self, parent):
service.MultiService.setServiceParent(self, parent)
if isinstance(parent, Componentized):
parent.setComponent(ILogObserver, rurouniLogObserver)
示例6: test_startUsesApplicationLogObserver
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log 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()
logs = []
application.setComponent(ILogObserver, logs.append)
logger = app.AppLogger({})
logger.start(application)
self._checkObserver(logs)
示例7: start
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log 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()