add logging to request handling

This commit is contained in:
Forrest Rice 2021-11-15 12:40:15 -08:00
parent 1ca199f9b3
commit a9b1f9d6ea
2 changed files with 12 additions and 1 deletions

View file

@ -57,4 +57,4 @@ from .signals import template_rendered
from .templating import render_template
from .templating import render_template_string
__version__ = "1.1.4"
__version__ = "1.1.4.dev1"

View file

@ -10,6 +10,7 @@
"""
import os
import sys
import threading
import warnings
from datetime import timedelta
from functools import update_wrapper
@ -1942,14 +1943,19 @@ class Flask(_PackageBoundObject):
.. versionadded:: 0.7
"""
thread_name = threading.currentThread().getName()
self.logger.info(f"{thread_name}: calling try_trigger_before_first_request_functions")
self.try_trigger_before_first_request_functions()
try:
self.logger.info(f"{thread_name}: calling preprocess_request")
request_started.send(self)
rv = self.preprocess_request()
if rv is None:
self.logger.info(f"{thread_name}: calling dispatch_request")
rv = self.dispatch_request()
except Exception as e:
rv = self.handle_user_exception(e)
self.logger.info(f"{thread_name}: calling finalize_request")
return self.finalize_request(rv)
def finalize_request(self, rv, from_error_handler=False):
@ -2439,11 +2445,15 @@ class Flask(_PackageBoundObject):
a list of headers, and an optional exception context to
start the response.
"""
thread_name = threading.currentThread().getName()
self.logger.info(f"{thread_name}: Creating request_context")
ctx = self.request_context(environ)
error = None
try:
try:
self.logger.info(f"{thread_name}: Pushing request_context")
ctx.push()
self.logger.info(f"{thread_name}: Calling dispatch")
response = self.full_dispatch_request()
except Exception as e:
error = e
@ -2453,6 +2463,7 @@ class Flask(_PackageBoundObject):
raise
return response(environ, start_response)
finally:
self.logger.info(f"{thread_name}: wsgi_app finally")
if self.should_ignore_error(error):
error = None
ctx.auto_pop(error)