Log exception tracebacks when they're available for error-messages
See ticket #100
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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"),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user