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


Python log.textFromEventDict方法代碼示例

本文整理匯總了Python中twisted.python.log.textFromEventDict方法的典型用法代碼示例。如果您正苦於以下問題:Python log.textFromEventDict方法的具體用法?Python log.textFromEventDict怎麽用?Python log.textFromEventDict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.python.log的用法示例。


在下文中一共展示了log.textFromEventDict方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_malformedHeaderCGI

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_malformedHeaderCGI(self):
        """
        Check for the error message in the duplicated header
        """
        cgiFilename = self.writeCGI(BROKEN_HEADER_CGI)

        portnum = self.startServer(cgiFilename)
        url = "http://localhost:%d/cgi" % (portnum,)
        agent = client.Agent(reactor)
        d = agent.request(b"GET", url)
        d.addCallback(discardBody)
        loggedMessages = []

        def addMessage(eventDict):
            loggedMessages.append(log.textFromEventDict(eventDict))

        log.addObserver(addMessage)
        self.addCleanup(log.removeObserver, addMessage)

        def checkResponse(ignored):
            self.assertIn("ignoring malformed CGI header: 'XYZ'",
                          loggedMessages)

        d.addCallback(checkResponse)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:27,代碼來源:test_cgi.py

示例2: test_logStderr

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_logStderr(self):
        """
        When the _errFlag is set to L{StandardErrorBehavior.LOG},
        L{endpoints._WrapIProtocol} logs stderr (in childDataReceived).
        """
        d = self.ep.connect(self.factory)
        self.successResultOf(d)
        wpp = self.reactor.processProtocol
        log.addObserver(self._stdLog)
        self.addCleanup(log.removeObserver, self._stdLog)

        wpp.childDataReceived(2, b'stderr1')
        self.assertEqual(self.eventLog['executable'], wpp.executable)
        self.assertEqual(self.eventLog['data'], b'stderr1')
        self.assertEqual(self.eventLog['protocol'], wpp.protocol)
        self.assertIn(
            'wrote stderr unhandled by',
            log.textFromEventDict(self.eventLog)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:test_endpoints.py

示例3: test_logErrorLogsErrorNoRepr

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_logErrorLogsErrorNoRepr(self):
        """
        The text logged by L{defer.logError} has no repr of the failure.
        """
        output = []

        def emit(eventDict):
            output.append(log.textFromEventDict(eventDict))

        log.addObserver(emit)

        error = failure.Failure(RuntimeError())
        defer.logError(error)
        self.flushLoggedErrors(RuntimeError)

        self.assertTrue(output[0].startswith("Unhandled Error\nTraceback ")) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_defer.py

示例4: test_errorLogNoRepr

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_errorLogNoRepr(self):
        """
        Verify that when a L{Deferred} with no references to it is fired,
        the logged message does not contain a repr of the failure object.
        """
        defer.Deferred().addCallback(lambda x: 1 // 0).callback(1)

        gc.collect()
        self._check()

        self.assertEqual(2, len(self.c))
        msg = log.textFromEventDict(self.c[-1])
        expected = "Unhandled Error\nTraceback "
        self.assertTrue(msg.startswith(expected),
                        "Expected message starting with: {0!r}".
                            format(expected)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_defer.py

示例5: test_errorLogDebugInfo

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_errorLogDebugInfo(self):
        """
        Verify that when a L{Deferred} with no references to it is fired,
        the logged message includes debug info if debugging on the deferred
        is enabled.
        """
        def doit():
            d = defer.Deferred()
            d.debug = True
            d.addCallback(lambda x: 1 // 0)
            d.callback(1)

        doit()
        gc.collect()
        self._check()

        self.assertEqual(2, len(self.c))
        msg = log.textFromEventDict(self.c[-1])
        expected = "(debug:  I"
        self.assertTrue(msg.startswith(expected),
                        "Expected message starting with: {0!r}".
                            format(expected)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:test_defer.py

示例6: test_connectionLostLogMsg

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_connectionLostLogMsg(self):
        """
        When a connection is lost, an informative message should be logged
        (see L{getExpectedConnectionLostLogMsg}): an address identifying
        the port and the fact that it was closed.
        """

        loggedMessages = []
        def logConnectionLostMsg(eventDict):
            loggedMessages.append(log.textFromEventDict(eventDict))

        reactor = self.buildReactor()
        p = self.getListeningPort(reactor, ServerFactory())
        expectedMessage = self.getExpectedConnectionLostLogMsg(p)
        log.addObserver(logConnectionLostMsg)

        def stopReactor(ignored):
            log.removeObserver(logConnectionLostMsg)
            reactor.stop()

        def doStopListening():
            log.addObserver(logConnectionLostMsg)
            maybeDeferred(p.stopListening).addCallback(stopReactor)

        reactor.callWhenRunning(doStopListening)
        reactor.run()

        self.assertIn(expectedMessage, loggedMessages) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:30,代碼來源:test_tcp.py

示例7: emit

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def emit(self, eventDict):
        """
        Produce a log output.
        """
        from twisted.trial._dist import managercommands
        text = textFromEventDict(eventDict)
        if text is None:
            return
        self.protocol.callRemote(managercommands.TestWrite, out=text) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:workertrial.py

示例8: emit

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def emit(self, eventDict):
        """
        Send a message event to the I{syslog}.

        @param eventDict: The event to send.  If it has no C{'message'} key, it
            will be ignored.  Otherwise, if it has C{'syslogPriority'} and/or
            C{'syslogFacility'} keys, these will be used as the syslog priority
            and facility.  If it has no C{'syslogPriority'} key but a true
            value for the C{'isError'} key, the B{LOG_ALERT} priority will be
            used; if it has a false value for C{'isError'}, B{LOG_INFO} will be
            used.  If the C{'message'} key is multiline, each line will be sent
            to the syslog separately.
        """
        # Figure out what the message-text is.
        text = log.textFromEventDict(eventDict)
        if text is None:
            return

        # Figure out what syslog parameters we might need to use.
        priority = syslog.LOG_INFO
        facility = 0
        if eventDict['isError']:
            priority = syslog.LOG_ALERT
        if 'syslogPriority' in eventDict:
            priority = int(eventDict['syslogPriority'])
        if 'syslogFacility' in eventDict:
            facility = int(eventDict['syslogFacility'])

        # Break the message up into lines and send them.
        lines = text.split('\n')
        while lines[-1:] == ['']:
            lines.pop()

        firstLine = True
        for line in lines:
            if firstLine:
                firstLine = False
            else:
                line = '\t' + line
            self.syslog(priority | facility,
                        '[%s] %s' % (eventDict['system'], line)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:43,代碼來源:syslog.py

示例9: test_formatMessage

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_formatMessage(self):
        """
        Using the message key, which is special in old-style, works for
        new-style formatting.
        """
        event = self.forwardAndVerify(
            dict(log_format="Hello, {message}!", message="world")
        )
        self.assertEqual(
            legacyLog.textFromEventDict(event),
            "Hello, world!"
        ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_legacy.py

示例10: test_formatAlreadySet

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_formatAlreadySet(self):
        """
        Formatting is not altered if the old-style C{"format"} key already
        exists.
        """
        event = self.forwardAndVerify(
            dict(log_format="Hello!", format="Howdy!")
        )
        self.assertEqual(legacyLog.textFromEventDict(event), "Howdy!") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_legacy.py

示例11: test_observed

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_observed(self):
        """
        The observer is called exactly once.
        """
        publishToNewObserver(
            self.observer, self.legacyEvent(), legacyLog.textFromEventDict
        )
        self.assertEqual(len(self.events), 1) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:10,代碼來源:test_legacy.py

示例12: test_time

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_time(self):
        """
        The old-style C{"time"} key is copied to the new-style C{"log_time"}
        key.
        """
        publishToNewObserver(
            self.observer, self.legacyEvent(), legacyLog.textFromEventDict
        )
        self.assertEqual(
            self.events[0]["log_time"], self.events[0]["time"]
        ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:test_legacy.py

示例13: test_message

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_message(self):
        """
        A published old-style event should format as text in the same way as
        the given C{textFromEventDict} callable would format it.
        """
        def textFromEventDict(event):
            return "".join(reversed(" ".join(event["message"])))

        event = self.legacyEvent("Hello,", "world!")
        text = textFromEventDict(event)

        publishToNewObserver(self.observer, event, textFromEventDict)
        self.assertEqual(formatEvent(self.events[0]), text) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:test_legacy.py

示例14: test_isError

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_isError(self):
        """
        If C{"isError"} is set to C{1} (true) on the legacy event, the
        C{"log_level"} key should get set to L{LogLevel.critical}.
        """
        publishToNewObserver(
            self.observer,
            self.legacyEvent(isError=1),
            legacyLog.textFromEventDict
        )
        self.assertEqual(self.events[0]["log_level"], LogLevel.critical) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:test_legacy.py

示例15: test_stdlibLogLevel

# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import textFromEventDict [as 別名]
def test_stdlibLogLevel(self):
        """
        If the old-style C{"logLevel"} key is set to a standard library logging
        level, using a predefined (L{int}) constant, the new-style
        C{"log_level"} key should get set to the corresponding log level.
        """
        publishToNewObserver(
            self.observer,
            self.legacyEvent(logLevel=py_logging.WARNING),
            legacyLog.textFromEventDict
        )
        self.assertEqual(self.events[0]["log_level"], LogLevel.warn) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_legacy.py


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