當前位置: 首頁>>代碼示例>>Python>>正文


Python log.ILogObserver方法代碼示例

本文整理匯總了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) 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:27,代碼來源:caldav.py

示例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) 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:27,代碼來源:test_caldav.py

示例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() 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:20,代碼來源:app.py

示例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 
開發者ID:canvasnetworks,項目名稱:canvas,代碼行數:18,代碼來源:server.py

示例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) 
開發者ID:douban,項目名稱:Kenshin,代碼行數:6,代碼來源:service.py

示例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) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:14,代碼來源:test_twistd.py

示例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() 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:48,代碼來源:app.py


注:本文中的twisted.python.log.ILogObserver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。