[pitivi] loggable: Remove twisted-related logic



commit 0df3bd0dea96e5cb7fff9de8c7343010e9dab489
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sun Feb 16 21:03:52 2014 +0100

    loggable: Remove twisted-related logic

 pitivi/utils/loggable.py |  156 ----------------------------------------------
 1 files changed, 0 insertions(+), 156 deletions(-)
---
diff --git a/pitivi/utils/loggable.py b/pitivi/utils/loggable.py
index 0b1bca4..1a231c8 100644
--- a/pitivi/utils/loggable.py
+++ b/pitivi/utils/loggable.py
@@ -1001,23 +1001,6 @@ class BaseLoggable(object):
         return doLog(level, self.logObjectName(), self.logCategory,
                   format, args, where=where, **kwargs)
 
-    def warningFailure(self, failure, swallow=True):
-        """
-        Log a warning about a Twisted Failure. Useful as an errback handler:
-        d.addErrback(self.warningFailure)
-
-        @param swallow: whether to swallow the failure or not
-        @type  swallow: bool
-        """
-        if _canShortcutLogging(self.logCategory, WARN):
-            if swallow:
-                return
-            return failure
-        warningObject(self.logObjectName(), self.logCategory,
-            *self.logFunction(getFailureMessage(failure)))
-        if not swallow:
-            return failure
-
     def logFunction(self, *args):
         """Overridable log function.  Default just returns passed message."""
         return args
@@ -1034,145 +1017,6 @@ class BaseLoggable(object):
     def handleException(self, exc):
         self.warning(getExceptionMessage(exc))
 
-# Twisted helper stuff
-
-# private stuff
-_initializedTwisted = False
-
-# make a singleton
-__theTwistedLogObserver = None
-
-
-def _getTheTwistedLogObserver():
-    # used internally and in test
-    global __theTwistedLogObserver
-
-    if not __theTwistedLogObserver:
-        __theTwistedLogObserver = TwistedLogObserver()
-
-    return __theTwistedLogObserver
-
-
-# public helper methods
-
-
-def getFailureMessage(failure):
-    """
-    Return a short message based on L{twisted.python.failure.Failure}.
-    Tries to find where the exception was triggered.
-    """
-    exc = str(failure.type)
-    msg = failure.getErrorMessage()
-    if len(failure.frames) == 0:
-        return "failure %(exc)s: %(msg)s" % locals()
-
-    (func, filename, line, some, other) = failure.frames[-1]
-    filename = scrubFilename(filename)
-    return "failure %(exc)s at %(filename)s:%(line)s: %(func)s(): %(msg)s" % locals()
-
-
-def warningFailure(failure, swallow=True):
-    """
-    Log a warning about a Failure. Useful as an errback handler:
-    d.addErrback(warningFailure)
-
-    @param swallow: whether to swallow the failure or not
-    @type  swallow: bool
-    """
-    warning('', getFailureMessage(failure))
-    if not swallow:
-        return failure
-
-
-def logTwisted():
-    """
-    Integrate twisted's logger with our logger.
-
-    This is done in a separate method because calling this imports and sets
-    up a reactor.  Since we want basic logging working before choosing a
-    reactor, we need to separate these.
-    """
-    global _initializedTwisted
-
-    if _initializedTwisted:
-        return
-
-    debug('log', 'Integrating twisted logger')
-
-    # integrate twisted's logging with us
-    from twisted.python import log as tlog
-
-    # this call imports the reactor
-    # that is why we do this in a separate method
-    from twisted.spread import pb
-
-    # we don't want logs for pb.Error types since they
-    # are specifically raised to be handled on the other side
-    observer = _getTheTwistedLogObserver()
-    observer.ignoreErrors([pb.Error, ])
-    tlog.startLoggingWithObserver(observer.emit, False)
-
-    _initializedTwisted = True
-
-
-# we need an object as the observer because startLoggingWithObserver
-# expects a bound method
-
-
-class TwistedLogObserver(BaseLoggable):
-    """
-    Twisted log observer that integrates with our logging.
-    """
-    logCategory = "logobserver"
-
-    def __init__(self):
-        self._ignoreErrors = []  # Failure types
-
-    def emit(self, eventDict):
-        method = log  # by default, lowest level
-        edm = eventDict['message']
-        if not edm:
-            if eventDict['isError'] and 'failure' in eventDict:
-                f = eventDict['failure']
-                for failureType in self._ignoreErrors:
-                    r = f.check(failureType)
-                    if r:
-                        self.debug("Failure of type %r, ignoring", failureType)
-                        return
-
-                self.log("Failure %r" % f)
-
-                method = debug  # tracebacks from errors at debug level
-                msg = "A twisted traceback occurred."
-                if getCategoryLevel("twisted") < WARN:
-                    msg += "  Run with debug level >= 2 to see the traceback."
-                # and an additional warning
-                warning('twisted', msg)
-                text = f.getTraceback()
-                safeprintf(sys.stderr, "\nTwisted traceback:\n")
-                safeprintf(sys.stderr, text + '\n')
-            elif 'format' in eventDict:
-                text = eventDict['format'] % eventDict
-            else:
-                # we don't know how to log this
-                return
-        else:
-            text = ' '.join(map(str, edm))
-
-        fmtDict = {'system': eventDict['system'],
-                   'text': text.replace("\n", "\n\t")}
-        msgStr = " [%(system)s] %(text)s\n" % fmtDict
-        # because msgstr can contain %, as in a backtrace, make sure we
-        # don't try to splice it
-        method('twisted', msgStr)
-
-    def ignoreErrors(self, *types):
-        for failureType in types:
-            self._ignoreErrors.append(failureType)
-
-    def clearIgnores(self):
-        self._ignoreErrors = []
-
 
 class Loggable(BaseLoggable):
     def __init__(self, logCategory=None):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]