1. Logging functionality added for internal server errors to aid diagnosis of live website bugs.
This commit is contained in:
Binary file not shown.
24
app.py
24
app.py
@@ -56,7 +56,9 @@ from flask_wtf.csrf import CSRFProtect
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
import os
|
||||
import sys
|
||||
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__)) # Todo: why?
|
||||
|
||||
@@ -100,6 +102,26 @@ with app.app_context():
|
||||
)
|
||||
|
||||
|
||||
# logging
|
||||
handler = RotatingFileHandler('app.log', maxBytes=10000, backupCount=3)
|
||||
handler.setLevel(logging.ERROR)
|
||||
app.logger.addHandler(handler)
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(error):
|
||||
app.logger.error('Server Error: %s', (error))
|
||||
app.logger.error('Request: %s %s %s %s %s',
|
||||
request.remote_addr,
|
||||
request.method,
|
||||
request.scheme,
|
||||
request.full_path,
|
||||
request.headers)
|
||||
app.logger.error('Request data: %s', request.get_data())
|
||||
app.logger.error('Traceback: %s', traceback.format_exc())
|
||||
return "500 Internal Server Error", 500
|
||||
|
||||
|
||||
|
||||
app.register_blueprint(routes_core)
|
||||
app.register_blueprint(routes_legal)
|
||||
app.register_blueprint(routes_store)
|
||||
|
||||
@@ -11,5 +11,5 @@ stripe
|
||||
python_dotenv
|
||||
authlib
|
||||
pydantic
|
||||
psycopg2
|
||||
# psycopg2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user