add logging to stdout
This commit is contained in:
parent
5e920ebbfe
commit
a754277c04
1 changed files with 5 additions and 22 deletions
27
app.py
27
app.py
|
@ -3,9 +3,8 @@ 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
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
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')
|
||||||
|
@ -15,27 +14,11 @@ VALID_FILENAME_REGEX = r'^[a-zA-Z0-9\-_\.]+$'
|
||||||
|
|
||||||
AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken')
|
AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken')
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
|
app.logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||||
# Configure root logger to output to stdout
|
app.logger.setLevel(logging.INFO)
|
||||||
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