1. Logging functionality added for internal server errors to aid diagnosis of live website bugs.

This commit is contained in:
2024-09-10 12:41:37 +01:00
parent 6b730bf8e7
commit caf642d5c5
4 changed files with 24 additions and 2 deletions

Binary file not shown.

0
app.log Normal file
View File

24
app.py
View File

@@ -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)

View File

@@ -11,5 +11,5 @@ stripe
python_dotenv
authlib
pydantic
psycopg2
# psycopg2