This repository was archived by the owner on Jun 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import logging
12import os
23
4+ from gunicorn .glogging import Logger
35from prometheus_client import multiprocess
46
57
68def 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+ """
15+ A custom class for logging gunicorn startup logs, these are for the logging that takes
16+ place before the Django app starts and takes over with its own defined logging formats.
17+ This class ensures the gunicorn minimum log level to be INFO instead of the default ERROR.
18+ """
19+
20+ def setup (self , cfg ):
21+ super ().setup (cfg )
22+ custom_format = "[%(levelname)s] [%(process)d] [%(asctime)s] %(message)s "
23+ date_format = "%Y-%m-%d %H:%M:%S %z"
24+ formatter = logging .Formatter (fmt = custom_format , datefmt = date_format )
25+
26+ # Update handlers with the custom formatter
27+ for handler in self .error_log .handlers :
28+ handler .setFormatter (formatter )
29+ for handler in self .access_log .handlers :
30+ handler .setFormatter (formatter )
31+
32+
33+ logconfig_dict = {
34+ "loggers" : {
35+ "gunicorn.error" : {
36+ "level" : "INFO" ,
37+ "handlers" : ["console" ],
38+ "propagate" : False ,
39+ },
40+ "gunicorn.access" : {
41+ "level" : "INFO" ,
42+ "handlers" : ["console" ],
43+ "propagate" : False ,
44+ },
45+ }
46+ }
47+
48+ logger_class = CustomGunicornLogger
You can’t perform that action at this time.
0 commit comments