Spaces:
Build error
Build error
Add log configuration to flask api
Browse files- api_rest/gunicorn.py +20 -1
api_rest/gunicorn.py
CHANGED
|
@@ -1,12 +1,31 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
| 2 |
import multiprocessing
|
| 3 |
import os
|
| 4 |
from distutils.util import strtobool
|
| 5 |
|
| 6 |
bind = f"0.0.0.0:{os.getenv('PORT', '8000')}"
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
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
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
workers = int(os.getenv("WEB_CONCURRENCY", multiprocessing.cpu_count() * 2))
|
| 11 |
threads = int(os.getenv("PYTHON_MAX_THREADS", 1))
|
| 12 |
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
import logging
|
| 3 |
+
from logging.handlers import RotatingFileHandler
|
| 4 |
import multiprocessing
|
| 5 |
import os
|
| 6 |
from distutils.util import strtobool
|
| 7 |
|
| 8 |
bind = f"0.0.0.0:{os.getenv('PORT', '8000')}"
|
| 9 |
+
|
| 10 |
+
if not os.path.exists('logs'):
|
| 11 |
+
os.makedirs('logs')
|
| 12 |
+
accesslog = "logs/access.log"
|
| 13 |
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
|
| 14 |
|
| 15 |
+
access_logger = logging.getLogger('gunicorn.access')
|
| 16 |
+
access_handler = RotatingFileHandler(
|
| 17 |
+
accesslog, maxBytes=1024 * 1024 * 100, backupCount=5)
|
| 18 |
+
access_logger.addHandler(access_handler)
|
| 19 |
+
|
| 20 |
+
errorlog = 'logs/app.log'
|
| 21 |
+
error_logger = logging.getLogger('gunicorn.error')
|
| 22 |
+
error_handler = RotatingFileHandler(
|
| 23 |
+
errorlog, maxBytes=1024 * 1024 * 100, backupCount=5)
|
| 24 |
+
error_logger.addHandler(error_handler)
|
| 25 |
+
|
| 26 |
+
if (os.environ.get('FLASK_DEBUG') == 'true'):
|
| 27 |
+
loglevel = 'debug'
|
| 28 |
+
|
| 29 |
workers = int(os.getenv("WEB_CONCURRENCY", multiprocessing.cpu_count() * 2))
|
| 30 |
threads = int(os.getenv("PYTHON_MAX_THREADS", 1))
|
| 31 |
|