向nonebot对齐了一下日志输出

This commit is contained in:
Bluemangoo 2026-07-05 18:40:09 +08:00
parent 737249b0d7
commit 1663c1945d
Signed by: Bluemangoo
GPG Key ID: F2F7E46880A1C4CF
2 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import nonebot
from nonebot import require
from nonebot import require, logger
require("nonebot_plugin_apscheduler")
@ -19,6 +19,10 @@ def startup():
rlib.set_proxy(pconfig.proxy)
if pconfig.github_token:
rlib.set_ghp(pconfig.github_token)
try:
rlib.set_log_level(logger._core.extra.get("nonebot_log_level", "INFO"))
except Exception as e:
logger.error(f"设置日志等级失败: {e}")
rlib.boot(str(Path.cwd()), "nonebot_plugin_sekai_update_notify", pconfig.assets_studio_path)
scheduler.add_job(sync, "interval", seconds=10, id="sekai_update_sync", replace_existing=True)

12
lib.py
View File

@ -25,6 +25,7 @@ class FetchData:
instance.card_paths = data.get("card_paths", [])
return instance
class SekaiSyncLib:
def __init__(self):
self.lib = ctypes.CDLL(os.path.join(os.path.dirname(__file__), get_lib_filename("sekai_sync_lib")))
@ -39,6 +40,10 @@ class SekaiSyncLib:
self.lib.ghp.argtypes = [ctypes.c_char_p]
self.lib.ghp.restype = None
# ghp(x: *const c_char)
self.lib.log_level.argtypes = [ctypes.c_char_p]
self.lib.log_level.restype = None
# boot(cwd: *const c_char, name: *const c_char, as_path: *const c_char) -> c_int
self.lib.boot.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
self.lib.boot.restype = ctypes.c_int
@ -71,6 +76,10 @@ class SekaiSyncLib:
"""设置 GitHub Token传 None 或空字符串可清除"""
self.lib.ghp(self._str_to_bytes(token))
def set_log_level(self, log_evel: Optional[str]):
"""设置 Log level传 None 或空字符串可清除"""
self.lib.log_level(self._str_to_bytes(log_evel))
def boot(self, cwd: str, name: str, as_path: str) -> int:
"""
启动主循环与初始化状态
@ -109,4 +118,5 @@ class SekaiSyncLib:
# 4. 无论是否发生 JSON 解析异常,绝对保证释放 Rust 内存!
self.lib.free_string(ptr)
rlib = SekaiSyncLib()
rlib = SekaiSyncLib()