yangdx commited on
Commit
1d5d470
·
1 Parent(s): a44a6ec

Unify two log filters into one and move it to utils

Browse files
lightrag/api/gunicorn_config.py CHANGED
@@ -59,7 +59,7 @@ logconfig_dict = {
59
  },
60
  "filters": {
61
  "path_filter": {
62
- "()": "lightrag.api.lightrag_server.LightragPathFilter",
63
  },
64
  },
65
  "loggers": {
 
59
  },
60
  "filters": {
61
  "path_filter": {
62
+ "()": "lightrag.utils.LightragPathFilter",
63
  },
64
  },
65
  "loggers": {
lightrag/api/lightrag_server.py CHANGED
@@ -55,41 +55,6 @@ config = configparser.ConfigParser()
55
  config.read("config.ini")
56
 
57
 
58
- class LightragPathFilter(logging.Filter):
59
- """Filter for lightrag logger to filter out frequent path access logs"""
60
-
61
- def __init__(self):
62
- super().__init__()
63
- # Define paths to be filtered
64
- self.filtered_paths = ["/documents", "/health", "/webui/"]
65
-
66
- def filter(self, record):
67
- try:
68
- # Check if record has the required attributes for an access log
69
- if not hasattr(record, "args") or not isinstance(record.args, tuple):
70
- return True
71
- if len(record.args) < 5:
72
- return True
73
-
74
- # Extract method, path and status from the record args
75
- method = record.args[1]
76
- path = record.args[2]
77
- status = record.args[4]
78
-
79
- # Filter out successful GET requests to filtered paths
80
- if (
81
- method == "GET"
82
- and (status == 200 or status == 304)
83
- and path in self.filtered_paths
84
- ):
85
- return False
86
-
87
- return True
88
- except Exception:
89
- # In case of any error, let the message through
90
- return True
91
-
92
-
93
  def create_app(args):
94
  # Setup logging
95
  logger.setLevel(args.log_level)
@@ -531,7 +496,7 @@ def configure_logging():
531
  },
532
  "filters": {
533
  "path_filter": {
534
- "()": "lightrag.api.lightrag_server.LightragPathFilter",
535
  },
536
  },
537
  }
 
55
  config.read("config.ini")
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def create_app(args):
59
  # Setup logging
60
  logger.setLevel(args.log_level)
 
496
  },
497
  "filters": {
498
  "path_filter": {
499
+ "()": "lightrag.utils.LightragPathFilter",
500
  },
501
  },
502
  }
lightrag/utils.py CHANGED
@@ -75,7 +75,8 @@ class LightragPathFilter(logging.Filter):
75
  def __init__(self):
76
  super().__init__()
77
  # Define paths to be filtered
78
- self.filtered_paths = ["/documents", "/health", "/webui/"]
 
79
 
80
  def filter(self, record):
81
  try:
 
75
  def __init__(self):
76
  super().__init__()
77
  # Define paths to be filtered
78
+ # self.filtered_paths = ["/documents", "/health", "/webui/"]
79
+ self.filtered_paths = ["/health", "/webui/"]
80
 
81
  def filter(self, record):
82
  try: