Fix/v0.2.4 bug llq (#366)
* [fix]Fix ID: 1004684 - Bug fixed. New "end_user_id" field added to the implicit memory interface. * [fix]Fix bug ID1004858 and standardize Neo4j log output * [changes]The main warehouse is associated with the sub-warehouse. * [fix]Fix ID: 1004684 - Bug fixed. New "end_user_id" field added to the implicit memory interface. * [fix]Fix bug ID1004858 and standardize Neo4j log output * [changes]The main warehouse is associated with the sub-warehouse. * [changes]Based on the AI review, the code has been corrected. * [changes]Recovery of Implicit Memory Interface
This commit is contained in:
@@ -38,6 +38,51 @@ class SensitiveDataLoggingFilter(logging.Filter):
|
||||
return True
|
||||
|
||||
|
||||
class Neo4jSuccessNotificationFilter(logging.Filter):
|
||||
"""Neo4j 日志过滤器:过滤成功状态的通知,保留真正的警告和错误
|
||||
|
||||
Neo4j 驱动会以 WARNING 级别记录所有数据库通知,包括成功的操作。
|
||||
这个过滤器会过滤掉状态码为 '00000' (成功) 的通知,只保留真正的警告和错误。
|
||||
|
||||
使用正则表达式进行更严格的匹配,避免误过滤无关的警告。
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
# 编译正则表达式以提高性能
|
||||
# 匹配 gql_status='00000' 或 gql_status="00000",确保是完整的状态码
|
||||
GQL_STATUS_PATTERN = re.compile(r"gql_status=['\"]00000['\"]")
|
||||
|
||||
# 匹配 status_description 中的成功完成消息
|
||||
# 使用单词边界确保精确匹配
|
||||
SUCCESS_DESC_PATTERN = re.compile(r"status_description=['\"]note:\s*successful\s+completion['\"]", re.IGNORECASE)
|
||||
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
"""
|
||||
过滤 Neo4j 成功通知
|
||||
|
||||
Args:
|
||||
record: 日志记录
|
||||
|
||||
Returns:
|
||||
True表示允许记录,False表示拒绝(过滤掉)
|
||||
"""
|
||||
# 只处理 WARNING 级别的日志
|
||||
if record.levelno != logging.WARNING:
|
||||
return True
|
||||
|
||||
# 检查是否是 Neo4j 的成功通知
|
||||
message = str(record.msg)
|
||||
|
||||
# 使用正则表达式进行更严格的匹配
|
||||
# 这样可以避免误过滤包含这些子字符串但不是 Neo4j 通知的日志
|
||||
if self.GQL_STATUS_PATTERN.search(message) or self.SUCCESS_DESC_PATTERN.search(message):
|
||||
return False # 过滤掉这条日志
|
||||
|
||||
# 保留其他所有日志(包括真正的警告和错误)
|
||||
return True
|
||||
|
||||
|
||||
class LoggingConfig:
|
||||
"""全局日志配置类"""
|
||||
|
||||
@@ -62,6 +107,14 @@ class LoggingConfig:
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(getattr(logging, settings.LOG_LEVEL.upper()))
|
||||
|
||||
# 为 Neo4j 驱动添加过滤器,过滤成功通知但保留真正的警告
|
||||
# Neo4j 驱动会以 WARNING 级别记录所有数据库通知,包括成功的操作(status='00000')
|
||||
# 使用过滤器而不是改变日志级别,这样可以保留真正的警告和错误
|
||||
neo4j_filter = Neo4jSuccessNotificationFilter()
|
||||
for neo4j_logger_name in ["neo4j", "neo4j.io", "neo4j.pool"]:
|
||||
neo4j_logger = logging.getLogger(neo4j_logger_name)
|
||||
neo4j_logger.addFilter(neo4j_filter)
|
||||
|
||||
# 清除现有处理器
|
||||
root_logger.handlers.clear()
|
||||
|
||||
|
||||
Submodule redbear-mem-benchmark updated: 4b0257bb4e...0c4bcafbc1
Reference in New Issue
Block a user