yangdx commited on
Commit
c0beaac
·
1 Parent(s): fdb6c2e

Update Gunicorn config with logging filters and worker-specific configurations

Browse files
Files changed (1) hide show
  1. gunicorn_config.py +25 -3
gunicorn_config.py CHANGED
@@ -1,10 +1,9 @@
1
  # gunicorn_config.py
2
  import os
3
  import logging
4
- from logging.config import dictConfig
5
- from logging.handlers import RotatingFileHandler
6
  from lightrag.kg.shared_storage import finalize_share_data
7
  from lightrag.api.utils_api import parse_args
 
8
 
9
  # Parse command line arguments
10
  args = parse_args()
@@ -64,6 +63,11 @@ logconfig_dict = {
64
  'encoding': 'utf8'
65
  }
66
  },
 
 
 
 
 
67
  'loggers': {
68
  'lightrag': {
69
  'handlers': ['console', 'file'],
@@ -83,7 +87,8 @@ logconfig_dict = {
83
  'gunicorn.access': {
84
  'handlers': ['console', 'file'],
85
  'level': 'INFO',
86
- 'propagate': False
 
87
  }
88
  }
89
  }
@@ -131,3 +136,20 @@ def on_exit(server):
131
  print("=" * 80)
132
  print("Gunicorn shutdown complete")
133
  print("=" * 80)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # gunicorn_config.py
2
  import os
3
  import logging
 
 
4
  from lightrag.kg.shared_storage import finalize_share_data
5
  from lightrag.api.utils_api import parse_args
6
+ from lightrag.api.lightrag_server import LightragPathFilter
7
 
8
  # Parse command line arguments
9
  args = parse_args()
 
63
  'encoding': 'utf8'
64
  }
65
  },
66
+ 'filters': {
67
+ 'path_filter': {
68
+ '()': 'lightrag.api.lightrag_server.LightragPathFilter',
69
+ },
70
+ },
71
  'loggers': {
72
  'lightrag': {
73
  'handlers': ['console', 'file'],
 
87
  'gunicorn.access': {
88
  'handlers': ['console', 'file'],
89
  'level': 'INFO',
90
+ 'propagate': False,
91
+ 'filters': ['path_filter']
92
  }
93
  }
94
  }
 
136
  print("=" * 80)
137
  print("Gunicorn shutdown complete")
138
  print("=" * 80)
139
+
140
+
141
+ def post_fork(server, worker):
142
+ """
143
+ Executed after a worker has been forked.
144
+ This is a good place to set up worker-specific configurations.
145
+ """
146
+ # Disable uvicorn.error logger in worker processes
147
+ uvicorn_error_logger = logging.getLogger("uvicorn.error")
148
+ uvicorn_error_logger.setLevel(logging.CRITICAL)
149
+ uvicorn_error_logger.handlers = []
150
+ uvicorn_error_logger.propagate = False
151
+
152
+ # Add log filter to uvicorn.access handler in worker processes
153
+ uvicorn_access_logger = logging.getLogger("uvicorn.access")
154
+ path_filter = LightragPathFilter()
155
+ uvicorn_access_logger.addFilter(path_filter)