wordle-solver / api_rest /gunicorn.py
santit96's picture
Add log configuration to flask api
1489119
raw
history blame
1.06 kB
# -*- coding: utf-8 -*-
import logging
from logging.handlers import RotatingFileHandler
import multiprocessing
import os
from distutils.util import strtobool
bind = f"0.0.0.0:{os.getenv('PORT', '8000')}"
if not os.path.exists('logs'):
os.makedirs('logs')
accesslog = "logs/access.log"
access_log_format = "%(h)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s' in %(D)sµs" # noqa: E501
access_logger = logging.getLogger('gunicorn.access')
access_handler = RotatingFileHandler(
accesslog, maxBytes=1024 * 1024 * 100, backupCount=5)
access_logger.addHandler(access_handler)
errorlog = 'logs/app.log'
error_logger = logging.getLogger('gunicorn.error')
error_handler = RotatingFileHandler(
errorlog, maxBytes=1024 * 1024 * 100, backupCount=5)
error_logger.addHandler(error_handler)
if (os.environ.get('FLASK_DEBUG') == 'true'):
loglevel = 'debug'
workers = int(os.getenv("WEB_CONCURRENCY", multiprocessing.cpu_count() * 2))
threads = int(os.getenv("PYTHON_MAX_THREADS", 1))
reload = bool(strtobool(os.getenv("WEB_RELOAD", "false")))