Skip to content

Commit 0a2db9b

Browse files
authored
Supports JSON logging for gunicorn process within Docker. #8665
Co-authored-by: Allen Hernandez <2349718+AllenSH12@users.noreply.github.com>
1 parent 12b263c commit 0a2db9b

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

pkg/docker/gunicorn_config.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
11
import gunicorn
2-
gunicorn.SERVER_SOFTWARE = 'Python'
2+
3+
# Can be resolved because of how Dockerfile organizes the code during build
4+
from config import JSON_LOGGER, CONSOLE_LOG_LEVEL, CONSOLE_LOG_FORMAT_JSON
5+
6+
gunicorn.SERVER_SOFTWARE = "Python"
7+
8+
if JSON_LOGGER:
9+
logconfig_dict = {
10+
"version": 1,
11+
"disable_existing_loggers": False,
12+
"root": {"level": CONSOLE_LOG_LEVEL, "handlers": []},
13+
"loggers": {
14+
"gunicorn.error": {
15+
"level": CONSOLE_LOG_LEVEL,
16+
"handlers": ["error_console"],
17+
"propagate": True,
18+
"qualname": "gunicorn.error",
19+
},
20+
"gunicorn.access": {
21+
"level": CONSOLE_LOG_LEVEL,
22+
"handlers": ["console"],
23+
"propagate": True,
24+
"qualname": "gunicorn.access",
25+
},
26+
},
27+
"handlers": {
28+
"console": {
29+
"class": "logging.StreamHandler",
30+
"formatter": "json",
31+
"stream": "ext://sys.stdout",
32+
},
33+
"error_console": {
34+
"class": "logging.StreamHandler",
35+
"formatter": "json",
36+
"stream": "ext://sys.stderr",
37+
},
38+
},
39+
"formatters": {
40+
"json": {
41+
"class": "jsonformatter.JsonFormatter",
42+
"format": CONSOLE_LOG_FORMAT_JSON,
43+
},
44+
},
45+
}

0 commit comments

Comments
 (0)