refactor: replace print() with structured logging across backend

Replace all print()/stderr logging with Python logging module using
logger = logging.getLogger(__name__) pattern for consistent log levels
and formatting. Extract score conversion to shared score_utils module.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 15:52:44 +08:00
parent 4bb50ae9c1
commit 37c0364e7e
19 changed files with 257 additions and 216 deletions
@@ -1,12 +1,15 @@
"""
迁移孤立文档到默认知识库
"""
import logging
from sqlalchemy.orm import Session
from ..core.database import get_db
from ..models.user import User
from ..models.knowledge_base import KnowledgeBase
from ..models.document import Document
logger = logging.getLogger(__name__)
def migrate_orphaned_documents():
"""将没有知识库的文档迁移到用户的默认知识库"""
@@ -40,12 +43,12 @@ def migrate_orphaned_documents():
doc.knowledge_base_id = default_kb.id
db.commit()
print(f"用户 {user.username}{len(orphaned_docs)} 个文档已迁移到默认知识库")
logger.info(f"用户 {user.username}{len(orphaned_docs)} 个文档已迁移到默认知识库")
print("孤立文档迁移完成")
logger.info("孤立文档迁移完成")
except Exception as e:
print(f"迁移失败: {str(e)}")
logger.error(f"迁移失败: {str(e)}")
db.rollback()
finally:
db.close()