-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a request time logging middleware (#2361)
added a request time logging middleware (#2361) --------- Co-authored-by: Vignesh Hari <[email protected]>
- Loading branch information
1 parent
0ee6d8a
commit d3a0162
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
import time | ||
|
||
|
||
class RequestTimeLoggingMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
self.logger = logging.getLogger("time_logging_middleware") | ||
|
||
def __call__(self, request): | ||
request.start_time = time.time() | ||
response = self.get_response(request) | ||
duration = time.time() - request.start_time | ||
self.logger.info(f"Request to {request.path} took {duration:.4f} seconds") | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters