add logging to stdout

This commit is contained in:
Michael Grote 2023-04-13 15:14:11 +02:00
parent 5e920ebbfe
commit a754277c04

27
app.py
View file

@ -3,9 +3,8 @@ import re
import uuid
from flask import Flask, request, jsonify, send_from_directory
import datetime
import logging
from logging.handlers import RotatingFileHandler
import sys
import logging
app = Flask(__name__)
app.config['UPLOAD_DIRECTORY'] = os.environ.get('UPLOAD_DIRECTORY', '/uploads')
@ -15,27 +14,11 @@ VALID_FILENAME_REGEX = r'^[a-zA-Z0-9\-_\.]+$'
AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken')
import sys
import logging
# 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)
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.INFO)
def is_valid_filename(filename):
return bool(re.match(VALID_FILENAME_REGEX, filename))