-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgunicorn.conf.py
70 lines (54 loc) · 1.95 KB
/
gunicorn.conf.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import logging
import os
from gunicorn import glogging
bind = f"0.0.0.0:{os.getenv('SERVICE_PORT', 8000)}"
max_requests = os.getenv("GUNICORN_MAX_REQUESTS", 0)
workers = 1
worker_class = "gevent"
worker_connections = os.getenv("GEVENT_GREENLETS", 128)
wsgi_app = "app:wsgi_app"
timeout = os.getenv("WORKER_STARTUP_TIMEOUT", 180)
loglevel = "info"
accesslog = "-"
errorlog = "-"
access_log_format = (
'"message": "%(r)s", "http_host": "%({http_host}i)s", "method": "%(m)s", "uri":'
' "%(U)s", "query_string": "%(q)s", "status": %(s)s, "user_agent": "%(a)s",'
' "remote_addr": "%(h)s", "rq_size": %(b)s, "rs_time_ms": %(M)s, "protocol":'
' "%(H)s"'
)
logconfig = None
class HealthCheckFilter(logging.Filter):
def filter(self, record):
if any(
[
'/health"' in record.getMessage(),
'/live"' in record.getMessage(),
'/metrics"' in record.getMessage(),
]
):
return os.getenv("DEBUG", "false") != "false"
return True
class CustomGunicornLogger(glogging.Logger):
def setup(self, cfg):
super().setup(cfg)
# Add filters to Gunicorn logger
logger = logging.getLogger("gunicorn.access")
logger.addFilter(HealthCheckFilter())
logger_class = CustomGunicornLogger
glogging.Logger.datefmt = "%Y-%m-%dT%H:%M:%S%z"
glogging.Logger.error_fmt = (
'{"@timestamp": "%(asctime)s", "logger_name": "gunico'
'rn", "pid": "%(process)d", "pname": "%(processName)s'
'", "level": "%(levelname)s", "message": "%(message)s"}'
)
glogging.Logger.access_fmt = (
'{"@timestamp": "%(asctime)s", "logger_name": "gunic'
'orn", "pid": "%(process)d", "pname": "%(processName)'
's", "level": "%(levelname)s", %(message)s}'
)
glogging.Logger.syslog_fmt = (
'{"@timestamp": "%(asctime)s", "logger_name": "gunico'
'rn", "pid": "%(process)d", "pname": "%(processName)s'
'", "level": "%(levelname)s", "message": "%(message)s}"'
)