Skip to content

Commit

Permalink
Log URL of each incoming request including the resolved parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvanb committed Nov 28, 2022
1 parent bc3cb9a commit da26635
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions vantage6-server/vantage6/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from werkzeug.exceptions import HTTPException
from flasgger import Swagger
from flask import (
Flask, make_response, current_app, request, send_from_directory
Flask, make_response, current_app, request, send_from_directory, Request
)
from flask_cors import CORS
from flask_jwt_extended import JWTManager
Expand Down Expand Up @@ -199,12 +199,30 @@ def configure_flask(self):
self.app.config["MAIL_USE_SSL"] = mail_config.get("MAIL_USE_SSL",
False)

def _get_request_path(request: Request) -> str:
"""
Return request extension of request URL, e.g.
http://localhost:5000/api/task/1 -> api/task/1
Parameters
----------
request: Request
Flask request object
Returns
-------
string:
The endpoint path of the request
"""
return request.url.replace(request.url_root, '')

# before request
@self.app.before_request
def do_before_request():
"""Before every flask request method."""
# Add log message before each request
log.debug(f"Received request: {request.method} {request.url_rule}")
log.debug(f"Received request: {request.method} "
f"{_get_request_path(request)}")

# This will obtain a (scoped) db session from the session factory
# that is linked to the flask request global `g`. In every endpoint
Expand Down

0 comments on commit da26635

Please sign in to comment.