Added logging for http responses
This commit is contained in:
parent
7c8fcf665e
commit
b5e5c14239
@ -1,4 +1,5 @@
|
|||||||
from flask import Flask
|
from flask import Flask, g, request
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
from app.MRE import blueprint as mre_blueprint
|
from app.MRE import blueprint as mre_blueprint
|
||||||
from .api import blueprint as api_blueprint
|
from .api import blueprint as api_blueprint
|
||||||
@ -33,4 +34,14 @@ def create_app(app_name: str='MRE') -> Flask:
|
|||||||
app.register_blueprint(mre_blueprint)
|
app.register_blueprint(mre_blueprint)
|
||||||
app.register_blueprint(api_blueprint)
|
app.register_blueprint(api_blueprint)
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def before_request():
|
||||||
|
g.start = time.time()
|
||||||
|
|
||||||
|
@app.after_request
|
||||||
|
def after_request(response):
|
||||||
|
request_time = time.time() - g.start
|
||||||
|
app.logger.info(f'HTTP request completed (method={request.method}, path={request.path}, request_time={request_time}, status_code={response.status_code}).')
|
||||||
|
return response
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user