print改为logger打印

This commit is contained in:
zqc
2026-02-03 09:15:37 +08:00
parent 42d7d24c4d
commit f6ea6082f3
5 changed files with 46 additions and 35 deletions

View File

@@ -5,7 +5,7 @@
import logging
import sys
from typing import Optional
from logging.handlers import RotatingFileHandler
from logging.handlers import TimedRotatingFileHandler
from config import settings
@@ -56,10 +56,11 @@ def setup_logger(
if log_file or settings.LOG_FILE:
file_path = log_file or settings.LOG_FILE
try:
file_handler = RotatingFileHandler(
file_handler = TimedRotatingFileHandler(
file_path,
maxBytes=10 * 1024 * 1024, # 10MB
backupCount=5,
when='midnight', # 每天午夜轮转
interval=1, # 间隔1天
backupCount=0, # 保留30天的日志
encoding='utf-8'
)
file_handler.setLevel(log_level)

View File

@@ -5,6 +5,9 @@ import websockets
import threading
import queue
from utils.logger import get_logger
logger = get_logger(__name__)
# ========================= WebSocket 服务线程 =========================
class WebSocketSender(threading.Thread):
def __init__(self, send_queue: queue.Queue, stop_event: threading.Event, ws_host: str, ws_port: int):
@@ -42,7 +45,7 @@ class WebSocketSender(threading.Thread):
async def _run_async(self):
async with websockets.serve(self._ws_handler, self.ws_host, self.ws_port):
print(f"[INFO] WebSocket server started at ws://{self.ws_host}:{self.ws_port}")
logger.info(f"[INFO] WebSocket server started at ws://{self.ws_host}:{self.ws_port}")
await self._broadcaster()
def run(self):