diff --git a/app.py b/app.py index e8e7c6c..51995dd 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,9 @@ import re import uuid from flask import Flask, request, jsonify, send_from_directory import datetime +import logging +from logging.handlers import RotatingFileHandler +import sys app = Flask(__name__) app.config['UPLOAD_DIRECTORY'] = os.environ.get('UPLOAD_DIRECTORY', '/uploads') @@ -12,6 +15,28 @@ VALID_FILENAME_REGEX = r'^[a-zA-Z0-9\-_\.]+$' AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken') + + +# Configure root logger to output to stdout +root = logging.getLogger() +root.setLevel(logging.DEBUG) +handler = logging.StreamHandler(sys.stdout) +handler.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +handler.setFormatter(formatter) +root.addHandler(handler) + +# Configure Flask logger to output to file +flask_logger = logging.getLogger('werkzeug') +flask_logger.setLevel(logging.DEBUG) +log_file = os.path.join(app.root_path, 'logs', 'app.log') +handler = RotatingFileHandler(log_file, maxBytes=10000000, backupCount=5) +handler.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +handler.setFormatter(formatter) +flask_logger.addHandler(handler) + + def is_valid_filename(filename): return bool(re.match(VALID_FILENAME_REGEX, filename))