Commit ada9bf03 authored by Tres Seaver's avatar Tres Seaver

Allow hooking logger for testing.

parent 5156b59f
...@@ -116,12 +116,19 @@ from transaction._compat import StringIO ...@@ -116,12 +116,19 @@ from transaction._compat import StringIO
_marker = object() _marker = object()
_TB_BUFFER = None _TB_BUFFER = None #unittests may hook
def _makeTracebackBuffer(): #unittests may hook def _makeTracebackBuffer():
if _TB_BUFFER is not None: if _TB_BUFFER is not None:
return _TB_BUFFER return _TB_BUFFER
return StringIO() return StringIO()
_LOGGER = None #unittests may hook
def _makeLogger():
if _LOGGER is not None:
return _LOGGER
return logging.getLogger("txn.%d" % get_thread_ident())
# The point of this is to avoid hiding exceptions (which the builtin # The point of this is to avoid hiding exceptions (which the builtin
# hasattr() does). # hasattr() does).
def myhasattr(obj, attr): def myhasattr(obj, attr):
...@@ -183,7 +190,7 @@ class Transaction(object): ...@@ -183,7 +190,7 @@ class Transaction(object):
# directly by storages, leading underscore notwithstanding. # directly by storages, leading underscore notwithstanding.
self._extension = {} self._extension = {}
self.log = logging.getLogger("txn.%d" % get_thread_ident()) self.log = _makeLogger()
self.log.debug("new transaction") self.log.debug("new transaction")
# If a commit fails, the traceback is saved in _failure_traceback. # If a commit fails, the traceback is saved in _failure_traceback.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment