Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 2ee753d

Browse files
committed
use gunicorn config file
1 parent e0be045 commit 2ee753d

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

codecov/settings_base.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@
219219
"datefmt": "%Y-%m-%dT%H:%M:%S%z",
220220
"format": '%(h)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"',
221221
},
222+
# "gunicorn_custom": {
223+
# "format": "[%(levelname)s] %(message)s [%(process)d] [%(asctime)s]",
224+
# "datefmt": "%Y-%m-%d %H:%M:%S %z",
225+
# },
222226
},
223227
"filters": {
224228
"health_check_filter": {"()": "utils.logging_configuration.HealthCheckFilter"}
@@ -240,18 +244,25 @@
240244
"formatter": "gunicorn_json",
241245
"class": "logging.StreamHandler",
242246
"stream": "ext://sys.stdout", # Default is stderr
243-
# "filters": ["health_check_filter"],
247+
"filters": ["health_check_filter"],
244248
},
249+
# "gunicorn-error-console": {
250+
# "level": "INFO",
251+
# "formatter": "gunicorn_custom",
252+
# "class": "logging.StreamHandler",
253+
# "stream": "ext://sys.stdout",
254+
# },
245255
},
246256
"loggers": {
247257
"gunicorn.access": {
248258
"level": "INFO",
249259
"handlers": ["json-gunicorn-console"],
250260
},
251-
"gunicorn.error": {
252-
"level": "INFO", # Adjust this to match your desired level
253-
"handlers": ["json-gunicorn-console"],
254-
},
261+
# "gunicorn.error": {
262+
# "level": "INFO",
263+
# "handlers": ["gunicorn-error-console"],
264+
# "propagate": False,
265+
# },
255266
},
256267
}
257268

dev.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# starts the development server using gunicorn
44
# NEVER run production with the --reload option command
5-
echo "Starting gunicorn in dev mode"
5+
echo "Starting gunicorn in dev mode dev.sh"
66

77
_start_gunicorn() {
88
if [ -n "$PROMETHEUS_MULTIPROC_DIR" ]; then
@@ -24,7 +24,7 @@ _start_gunicorn() {
2424
pip install debugpy
2525
python -m debugpy --listen 0.0.0.0:12345 -m gunicorn codecov.wsgi:application --reload --bind 0.0.0.0:8000 --access-logfile '-' --timeout "${GUNICORN_TIMEOUT:-600}" $suffix
2626
fi
27-
gunicorn codecov.wsgi:application --reload --bind 0.0.0.0:8000 --access-logfile '-' --timeout "${GUNICORN_TIMEOUT:-600}" $suffix
27+
gunicorn codecov.wsgi:application --log-level=info --reload --bind 0.0.0.0:8000 --access-logfile '-' --timeout "${GUNICORN_TIMEOUT:-600}" $suffix
2828
}
2929

3030
if [ -z "$1" ];

gunicorn.conf.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
1+
import logging
12
import os
23

4+
from gunicorn.glogging import Logger
35
from prometheus_client import multiprocess
46

57

68
def child_exit(server, worker):
79
if worker and worker.pid and "PROMETHEUS_MULTIPROC_DIR" in os.environ:
810
multiprocess.mark_process_dead(worker.pid)
11+
12+
13+
class CustomGunicornLogger(Logger):
14+
def setup(self, cfg):
15+
super().setup(cfg)
16+
custom_format = "[%(levelname)s] %(message)s [%(process)d] [%(asctime)s]"
17+
date_format = "%Y-%m-%d %H:%M:%S %z"
18+
formatter = logging.Formatter(fmt=custom_format, datefmt=date_format)
19+
20+
# Update handlers with the custom formatter
21+
for handler in self.error_log.handlers:
22+
handler.setFormatter(formatter)
23+
for handler in self.access_log.handlers:
24+
handler.setFormatter(formatter)
25+
26+
27+
logconfig_dict = {
28+
"loggers": {
29+
"gunicorn.error": {
30+
"level": "INFO",
31+
"handlers": ["console"],
32+
"propagate": False,
33+
},
34+
"gunicorn.access": {
35+
"level": "INFO",
36+
"handlers": ["console"],
37+
"propagate": False,
38+
},
39+
}
40+
}
41+
42+
# Update Gunicorn's `logger_class` to use the custom logger
43+
logger_class = CustomGunicornLogger

0 commit comments

Comments
 (0)