Python twisted.python.log 模块,ILogObserver() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用twisted.python.log.ILogObserver()

项目:flora    作者:Lamden    | 项目源码 | 文件源码
def __init__(self, *args):
        self.ip = args[0]
        self.port = args[1]

        application = service.Application("kademlia")
        application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)

        if os.path.isfile('cache.pickle'):
            kserver = Server.loadState('cache.pickle')
        else:
            kserver = Server()
            kserver.bootstrap([(self.ip, self.port)])
        kserver.saveStateRegularly('cache.pickle', 10)

        server = internet.UDPServer(self.port, kserver.protocol)
        server.setServiceParent(application)

        self.log = logging.getLogger(resource_filename(__name__, __file__))
项目:fluiddb    作者:fluidinfo    | 项目源码 | 文件源码
def setupTwistedLogging(application):
    """Setup a L{LogFile} for the given application.

    @param application: A C{twisted.application.service.Application} instance.
    """
    application.setComponent(ILogObserver, PythonLoggingObserver(None).emit)
项目:Kenshin    作者:douban    | 项目源码 | 文件源码
def setServiceParent(self, parent):
        service.MultiService.setServiceParent(self, parent)
        if isinstance(parent, Componentized):
            parent.setComponent(ILogObserver, rurouniLogObserver)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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()