diff --git a/test/test_logging.py b/test/test_logging.py index dfbfaa1..1820b10 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -141,6 +141,17 @@ def test_info(handler, framework): assert handler.messages[0].endswith(b"hilarious elephant") +def test_legacy_error_with_traceback(handler, framework): + import logging + + try: + raise RuntimeError("the bad stuff") + except Exception: + logging.error("bad stuff", exc_info=True) + + assert 'RuntimeError: the bad stuff' in str(handler.messages) + + def test_trace(handler, framework): logger = txaio.make_logger() old_log = txaio.get_global_log_level() diff --git a/txaio/aio.py b/txaio/aio.py index 9c2f871..55d3ca5 100644 --- a/txaio/aio.py +++ b/txaio/aio.py @@ -209,6 +209,10 @@ class _TxaioFileHandler(logging.Handler, object): dt = datetime.fromtimestamp(record.args.get('log_time', 0)) else: message = record.getMessage() + if record.levelno == logging.ERROR and record.exc_info: + message += '\n' + for line in traceback.format_exception(*record.exc_info): + message = message + line dt = datetime.fromtimestamp(record.created) msg = u'{0} {1}{2}'.format( dt.strftime("%Y-%m-%dT%H:%M:%S%z"),