Merge pull request #1080 from danielaskdd/main

Consolidate the two log filters into a single utility and relocate it to the utils module.
This commit is contained in:
Daniel.y
2025-03-13 17:54:48 +08:00
committed by GitHub
3 changed files with 3 additions and 37 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)
@@ -519,7 +484,7 @@ def configure_logging():
}, },
"filters": { "filters": {
"path_filter": { "path_filter": {
"()": "lightrag.api.lightrag_server.LightragPathFilter", "()": "lightrag.utils.LightragPathFilter",
}, },
}, },
} }

View File

@@ -76,6 +76,7 @@ class LightragPathFilter(logging.Filter):
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: