diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc index b2d92a9d..8097bb1e 100644 Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ diff --git a/app.log b/app.log new file mode 100644 index 00000000..e69de29b diff --git a/app.py b/app.py index e63b6477..3b25b115 100644 --- a/app.py +++ b/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) diff --git a/requirements.txt b/requirements.txt index 002ef30f..fe8064e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,5 +11,5 @@ stripe python_dotenv authlib pydantic -psycopg2 +# psycopg2