def on_tearing_down(sender, **kwargs): if g.get('req_end_sent'): return g.req_end_sent = True stats = get_request_stats() if not stats['query_count']: return logger.debug('Request finished', extra={'sql_log_type': 'end_request', 'sql_query_count': stats['query_count'], 'repl': app.config.get('REPL'), 'req_verb': request.method if has_request_context() else None, 'req_url': request.url if has_request_context() else None, 'req_path': request.path if has_request_context() else None, 'req_duration': stats['req_duration'], 'req_query_duration': stats['query_duration']})