add logging
This commit is contained in:
parent
08a6f84b17
commit
5e920ebbfe
1 changed files with 25 additions and 0 deletions
25
app.py
25
app.py
|
@ -3,6 +3,9 @@ import re
|
||||||
import uuid
|
import uuid
|
||||||
from flask import Flask, request, jsonify, send_from_directory
|
from flask import Flask, request, jsonify, send_from_directory
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
|
import sys
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['UPLOAD_DIRECTORY'] = os.environ.get('UPLOAD_DIRECTORY', '/uploads')
|
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')
|
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):
|
def is_valid_filename(filename):
|
||||||
return bool(re.match(VALID_FILENAME_REGEX, filename))
|
return bool(re.match(VALID_FILENAME_REGEX, filename))
|
||||||
|
|
||||||
|
|
Reference in a new issue