def default_exception_handler(self, context): """ Default exception handling. Thanks to asyncio for this function! """ message = context.get('message') if not message: message = 'Unhandled exception in event loop' exception = context.get('exception') if exception is not None: tb = get_traceback_from_context(context) exc_info = (type(exception), exception, tb) else: exc_info = False log_lines = [message] for key in sorted(context): if key in ('message', 'exception'): continue value = context[key] value = repr(value) log_lines.append('{}: {}'.format(key, value)) logger.error('\n'.join(log_lines), exc_info=exc_info)
def default_exception_handler(self, context): """ Default exception handling. Thanks to asyncio for this function! """ message = context.get('message') if not message: message = 'Unhandled exception in event loop' exception = context.get('exception') if exception is not None: tb = get_traceback_from_context(context) exc_info = (type(exception), exception, tb) else: exc_info = False log_lines = [message] for key in sorted(context): if key in ('message', 'exception'): continue value = context[key] value = repr(value) log_lines.append('{}: {}'.format(key, value)) logger.error('\n'.join(log_lines), exc_info=exc_info)
def call_exception_handler(self, context): """ Call the current event loop exception handler. (Similar to ``asyncio.BaseEventLoop.call_exception_handler``.) """ if self._exception_handler: try: self._exception_handler(context) except Exception: logger.error('Exception in default exception handler', exc_info=True) else: try: self.default_exception_handler(context) except Exception: logger.error('Exception in default exception handler ' 'while handling an unexpected error ' 'in custom exception handler', exc_info=True)
def call_exception_handler(self, context): """ Call the current event loop exception handler. (Similar to ``asyncio.BaseEventLoop.call_exception_handler``.) """ if self._exception_handler: try: self._exception_handler(context) except Exception: logger.error('Exception in default exception handler', exc_info=True) else: try: self.default_exception_handler(context) except Exception: logger.error('Exception in default exception handler ' 'while handling an unexpected error ' 'in custom exception handler', exc_info=True)