mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-11 18:10:06 +08:00
feat(app): 添加日志记录功能
- 新增 logger 模块,用于全局日志记录 - 在关键位置添加日志输出,包括事件处理、文件清理、FFmpeg 检查等 - 优化数据库操作,增加日志记录 - 在主程序启动时添加日志输出
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
from .sqlite_client import get_connection
|
||||
|
||||
from app.utils.logger import get_logger
|
||||
logger = get_logger(__name__)
|
||||
def init_video_task_table():
|
||||
conn = get_connection()
|
||||
if conn is None:
|
||||
logger.error("Failed to connect to the database.")
|
||||
return
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS video_tasks (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -12,41 +17,62 @@ def init_video_task_table():
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
try:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
logger.info("video_tasks table created successfully.")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create video_tasks table: {e}")
|
||||
|
||||
def insert_video_task(video_id: str, platform: str, task_id: str):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
INSERT INTO video_tasks (video_id, platform, task_id)
|
||||
VALUES (?, ?, ?)
|
||||
""", (video_id, platform, task_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
try:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
INSERT INTO video_tasks (video_id, platform, task_id)
|
||||
VALUES (?, ?, ?)
|
||||
""", (video_id, platform, task_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
logger.info(f"Video task inserted successfully."
|
||||
f"video_id: {video_id}"
|
||||
f"platform: {platform}"
|
||||
f"task_id: {task_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to insert video task: {e}")
|
||||
|
||||
|
||||
def get_task_by_video(video_id: str, platform: str):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT task_id FROM video_tasks
|
||||
WHERE video_id = ? AND platform = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
""", (video_id, platform))
|
||||
result = cursor.fetchone()
|
||||
conn.close()
|
||||
return result[0] if result else None
|
||||
try:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT task_id FROM video_tasks
|
||||
WHERE video_id = ? AND platform = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
""", (video_id, platform))
|
||||
result = cursor.fetchone()
|
||||
conn.close()
|
||||
if result is None:
|
||||
logger.info(f"No task found for video_id: {video_id} and platform: {platform}")
|
||||
logger.info(f"Task found for video_id: {video_id} and platform: {platform}")
|
||||
return result[0] if result else None
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get task by video: {e}")
|
||||
|
||||
|
||||
def delete_task_by_video(video_id: str, platform: str):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
DELETE FROM video_tasks
|
||||
WHERE video_id = ? AND platform = ?
|
||||
""", (video_id, platform))
|
||||
try:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
DELETE FROM video_tasks
|
||||
WHERE video_id = ? AND platform = ?
|
||||
""", (video_id, platform))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
conn.commit()
|
||||
conn.close()
|
||||
logger.info(f"Task deleted for video_id: {video_id} and platform: {platform}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to delete task by video: {e}")
|
||||
Reference in New Issue
Block a user