summaryrefslogtreecommitdiffstats
path: root/deluge/log.py
diff options
context:
space:
mode:
authorbendikro <bro.devel+deluge@gmail.com>2016-05-01 16:38:19 +0200
committerCalum Lind <calumlind+deluge@gmail.com>2016-05-06 12:44:45 +0100
commit6adbd14bf882f5edd8205dd5853d647d8be8680f (patch)
tree4a9457e232ba4c44ea8daa05a5b9e6e103eaa44a /deluge/log.py
parent58264465091167e99569ffc0e0f5de10dfda1801 (diff)
downloaddeluge-6adbd14bf882f5edd8205dd5853d647d8be8680f.tar.gz
deluge-6adbd14bf882f5edd8205dd5853d647d8be8680f.tar.bz2
deluge-6adbd14bf882f5edd8205dd5853d647d8be8680f.zip
[Base] Add custom log observer to handle twisted errors
For some reason errors are logged by twisted as 'Unhandled error in Deferred', but without a following stacktrace. This can happen in a deferred callback that e.g. raises an ImportError. Without an excplicit error handler for a deferred to log such errors, finding the error can be very tricky. Fix this by using a custom twisted.python.log.PythonLoggingObserver, PythonLoggingObserver, that also logs the traceback in addition to the error message.
Diffstat (limited to 'deluge/log.py')
-rw-r--r--deluge/log.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/deluge/log.py b/deluge/log.py
index 4e0b27e4e..4c2c9b620 100644
--- a/deluge/log.py
+++ b/deluge/log.py
@@ -153,11 +153,29 @@ def setup_logger(level="error", filename=None, filemode="w", logrotate=None):
root_logger.addHandler(handler)
root_logger.setLevel(level)
- twisted_logging = PythonLoggingObserver("twisted")
+ twisted_logging = TwistedLoggingObserver()
twisted_logging.start()
logging.getLogger("twisted").setLevel(level)
+class TwistedLoggingObserver(PythonLoggingObserver):
+
+ def __init__(self):
+ PythonLoggingObserver.__init__(self, loggerName='twisted')
+
+ def emit(self, event_dict):
+ log = logging.getLogger(__name__)
+ try:
+ fmt = "%(log_namespace)s "
+ if event_dict.get("log_format", None):
+ fmt += event_dict["log_format"]
+ if event_dict["isError"] and "failure" in event_dict:
+ fmt += "\n%(failure)s "
+ getattr(LoggingLoggerClass, event_dict["log_level"].name)(log, fmt % (event_dict))
+ except (KeyError, AttributeError) as ex:
+ log.error("ERROR when logging twisted error: '%s'", ex)
+
+
def tweak_logging_levels():
"""This function allows tweaking the logging levels for all or some loggers.
This is mostly usefull for developing purposes hence the contents of the