From 0a2db9bc59983195a09f7dd85e089b3af2edd847 Mon Sep 17 00:00:00 2001 From: Allen Hernandez Date: Tue, 3 Jun 2025 04:03:09 -0400 Subject: [PATCH] Supports JSON logging for gunicorn process within Docker. #8665 Co-authored-by: Allen Hernandez <2349718+AllenSH12@users.noreply.github.com> --- pkg/docker/gunicorn_config.py | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/pkg/docker/gunicorn_config.py b/pkg/docker/gunicorn_config.py index 513c889fe..ac7afe081 100644 --- a/pkg/docker/gunicorn_config.py +++ b/pkg/docker/gunicorn_config.py @@ -1,2 +1,45 @@ import gunicorn -gunicorn.SERVER_SOFTWARE = 'Python' + +# Can be resolved because of how Dockerfile organizes the code during build +from config import JSON_LOGGER, CONSOLE_LOG_LEVEL, CONSOLE_LOG_FORMAT_JSON + +gunicorn.SERVER_SOFTWARE = "Python" + +if JSON_LOGGER: + logconfig_dict = { + "version": 1, + "disable_existing_loggers": False, + "root": {"level": CONSOLE_LOG_LEVEL, "handlers": []}, + "loggers": { + "gunicorn.error": { + "level": CONSOLE_LOG_LEVEL, + "handlers": ["error_console"], + "propagate": True, + "qualname": "gunicorn.error", + }, + "gunicorn.access": { + "level": CONSOLE_LOG_LEVEL, + "handlers": ["console"], + "propagate": True, + "qualname": "gunicorn.access", + }, + }, + "handlers": { + "console": { + "class": "logging.StreamHandler", + "formatter": "json", + "stream": "ext://sys.stdout", + }, + "error_console": { + "class": "logging.StreamHandler", + "formatter": "json", + "stream": "ext://sys.stderr", + }, + }, + "formatters": { + "json": { + "class": "jsonformatter.JsonFormatter", + "format": CONSOLE_LOG_FORMAT_JSON, + }, + }, + }