Unify two log filters into one and move it to utils

This commit is contained in:
yangdx
2025-03-13 17:39:06 +08:00
parent 3b6fabca0e
commit 6893e3c4e2
3 changed files with 4 additions and 38 deletions

View File

@@ -59,7 +59,7 @@ logconfig_dict = {
}, },
"filters": { "filters": {
"path_filter": { "path_filter": {
"()": "lightrag.api.lightrag_server.LightragPathFilter", "()": "lightrag.utils.LightragPathFilter",
}, },
}, },
"loggers": { "loggers": {

View File

@@ -55,41 +55,6 @@ config = configparser.ConfigParser()
config.read("config.ini") config.read("config.ini")
class LightragPathFilter(logging.Filter):
"""Filter for lightrag logger to filter out frequent path access logs"""
def __init__(self):
super().__init__()
# Define paths to be filtered
self.filtered_paths = ["/documents", "/health", "/webui/"]
def filter(self, record):
try:
# Check if record has the required attributes for an access log
if not hasattr(record, "args") or not isinstance(record.args, tuple):
return True
if len(record.args) < 5:
return True
# Extract method, path and status from the record args
method = record.args[1]
path = record.args[2]
status = record.args[4]
# Filter out successful GET requests to filtered paths
if (
method == "GET"
and (status == 200 or status == 304)
and path in self.filtered_paths
):
return False
return True
except Exception:
# In case of any error, let the message through
return True
def create_app(args): def create_app(args):
# Setup logging # Setup logging
logger.setLevel(args.log_level) logger.setLevel(args.log_level)
@@ -531,7 +496,7 @@ def configure_logging():
}, },
"filters": { "filters": {
"path_filter": { "path_filter": {
"()": "lightrag.api.lightrag_server.LightragPathFilter", "()": "lightrag.utils.LightragPathFilter",
}, },
}, },
} }

View File

@@ -75,7 +75,8 @@ class LightragPathFilter(logging.Filter):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# Define paths to be filtered # Define paths to be filtered
self.filtered_paths = ["/documents", "/health", "/webui/"] # self.filtered_paths = ["/documents", "/health", "/webui/"]
self.filtered_paths = ["/health", "/webui/"]
def filter(self, record): def filter(self, record):
try: try: