Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from app import app
# Setup logging
import logging
from logging.handlers import RotatingFileHandler
from logging import Formatter
format = "[%(asctime)s] p%(process)s\n" \
"[%(levelname)s] in %(name)s: %(filename)s:%(lineno)d\n" \
"%(message)s\n"
logging.basicConfig(
filename=app.config.get('LOG_FILENAME', 'logs/flask.log'),
level=logging.DEBUG,
datefmt="%Y-%m-%d %H:%M:%S",
format = format
)
logging.info(
"\n"
"==============================================================\n"
"Mega-fMRI stimulus Rating Tool Flask application started\n"
"PET-keskus (2018) \n"
)
handler = RotatingFileHandler('logs/flask.log', maxBytes=10000, backupCount=5)
handler.setFormatter(
Formatter(format)
)
app.logger.addHandler(handler)
# Logging for production (nginx + gunicorn)
import os
is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")
if is_gunicorn:
app.logger.info("Application run through gunicorn")
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
app.logger.info("******************")
'''
else:
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
'''
# EOF