mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-18 14:26:24 +00:00
[Base] Updated fix for missing trace with new twisted logger
Includes a commented out test to replicate the issue.
This commit is contained in:
parent
919e41f55e
commit
1fb9960168
@ -155,25 +155,27 @@ def setup_logger(level="error", filename=None, filemode="w", logrotate=None):
|
|||||||
|
|
||||||
twisted_logging = TwistedLoggingObserver()
|
twisted_logging = TwistedLoggingObserver()
|
||||||
twisted_logging.start()
|
twisted_logging.start()
|
||||||
logging.getLogger("twisted").setLevel(level)
|
|
||||||
|
|
||||||
|
|
||||||
class TwistedLoggingObserver(PythonLoggingObserver):
|
class TwistedLoggingObserver(PythonLoggingObserver):
|
||||||
|
"""
|
||||||
|
Custom logging class to fix missing exception tracebacks in log output with new
|
||||||
|
twisted.logger module in twisted version >= 15.2.
|
||||||
|
|
||||||
|
Related twisted bug ticket: https://twistedmatrix.com/trac/ticket/7927
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
PythonLoggingObserver.__init__(self, loggerName='twisted')
|
PythonLoggingObserver.__init__(self, loggerName='twisted')
|
||||||
|
|
||||||
def emit(self, event_dict):
|
def emit(self, event_dict):
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
try:
|
if "log_failure" in event_dict:
|
||||||
fmt = "%(log_namespace)s "
|
fmt = "%(log_namespace)s \n%(log_failure)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))
|
getattr(LoggingLoggerClass, event_dict["log_level"].name)(log, fmt % (event_dict))
|
||||||
except (KeyError, AttributeError) as ex:
|
else:
|
||||||
log.error("ERROR when logging twisted error: '%s'", ex)
|
PythonLoggingObserver.emit(self, event_dict)
|
||||||
|
|
||||||
|
|
||||||
def tweak_logging_levels():
|
def tweak_logging_levels():
|
||||||
|
@ -30,3 +30,19 @@ class LogTestCase(BaseTestCase):
|
|||||||
warnings.simplefilter("always")
|
warnings.simplefilter("always")
|
||||||
LOG.debug("foo")
|
LOG.debug("foo")
|
||||||
self.assertEqual(w[-1].category, DeprecationWarning)
|
self.assertEqual(w[-1].category, DeprecationWarning)
|
||||||
|
|
||||||
|
# def test_twisted_error_log(self):
|
||||||
|
# from twisted.internet import defer
|
||||||
|
# import deluge.component as component
|
||||||
|
# from deluge.core.eventmanager import EventManager
|
||||||
|
# EventManager()
|
||||||
|
#
|
||||||
|
# d = component.start()
|
||||||
|
#
|
||||||
|
# @defer.inlineCallbacks
|
||||||
|
# def call(*args):
|
||||||
|
# yield component.pause(["EventManager"])
|
||||||
|
# yield component.start(["EventManager"])
|
||||||
|
#
|
||||||
|
# d.addCallback(call)
|
||||||
|
# return d
|
||||||
|
Loading…
x
Reference in New Issue
Block a user