mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
fix:过滤8000端口使用https访问时报错日志
This commit is contained in:
parent
381f8ea578
commit
6120d49a35
1 changed files with 28 additions and 1 deletions
|
|
@ -1,8 +1,35 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import logging
|
||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
|
|
||||||
|
|
||||||
|
class SuppressInvalidHandshakeFilter(logging.Filter):
|
||||||
|
"""过滤掉无效握手错误日志(如HTTPS访问WS端口)"""
|
||||||
|
|
||||||
|
def filter(self, record):
|
||||||
|
msg = record.getMessage()
|
||||||
|
suppress_keywords = [
|
||||||
|
"opening handshake failed",
|
||||||
|
"did not receive a valid HTTP request",
|
||||||
|
"connection closed while reading HTTP request",
|
||||||
|
"line without CRLF",
|
||||||
|
]
|
||||||
|
return not any(keyword in msg for keyword in suppress_keywords)
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_websockets_logger():
|
||||||
|
"""配置 websockets 相关的所有 logger,过滤无效握手错误"""
|
||||||
|
filter_instance = SuppressInvalidHandshakeFilter()
|
||||||
|
for logger_name in ["websockets", "websockets.server", "websockets.client"]:
|
||||||
|
logger = logging.getLogger(logger_name)
|
||||||
|
logger.addFilter(filter_instance)
|
||||||
|
|
||||||
|
|
||||||
|
_setup_websockets_logger()
|
||||||
|
|
||||||
|
|
||||||
from core.connection import ConnectionHandler
|
from core.connection import ConnectionHandler
|
||||||
from config.config_loader import get_config_from_api_async
|
from config.config_loader import get_config_from_api_async
|
||||||
from core.auth import AuthManager, AuthenticationError
|
from core.auth import AuthManager, AuthenticationError
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue