From 046e9edeab6b83f3c0752864c8a43c43e8435b07 Mon Sep 17 00:00:00 2001 From: Chenwe_i_lin <1846913566@qq.com> Date: Sat, 29 Feb 2020 20:18:12 +0800 Subject: [PATCH] improve: logbook log level --- mirai/logger.py | 11 ++++++++--- mirai/session.py | 7 ++++--- test.py | 3 +-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/mirai/logger.py b/mirai/logger.py index 233e0e3..8edf971 100644 --- a/mirai/logger.py +++ b/mirai/logger.py @@ -1,7 +1,12 @@ from logbook import Logger, StreamHandler +from logbook import ( + INFO, + DEBUG +) import sys -StreamHandler(sys.stdout, level=20).push_application() +StreamHandler(sys.stdout, level=INFO).push_application() -Event = Logger('Event', level=20) -Network = Logger("Network", level=10) +Event = Logger('Event', level=INFO) +Network = Logger("Network", level=DEBUG) +Session = Logger("Session", level=INFO) diff --git a/mirai/session.py b/mirai/session.py index a5cb44a..d4d7604 100644 --- a/mirai/session.py +++ b/mirai/session.py @@ -16,7 +16,7 @@ import inspect from functools import partial import copy -from .logger import Event as EventLogger +from .logger import Event as EventLogger, Session as SessionLogger import json _T = T.TypeVar("T") @@ -270,7 +270,7 @@ async def event_runner(self, exit_signal_status, queue: asyncio.Queue): if event_context.name in self.registeredEventNames: for event in list(self.event.values())\ [self.registeredEventNames.index(event_context.name)]: - if event: # 判断是否有注册. + if event: # 判断是否是 []/{} for pre_condition, run_body in event.items(): try: condition_result = (not pre_condition) or (pre_condition(event_context.body)) @@ -278,7 +278,7 @@ async def event_runner(self, exit_signal_status, queue: asyncio.Queue): self.throw_exception_event(event_context, queue, e) continue if condition_result: - EventLogger.info(f"handling a event: {event_context}") + EventLogger.info(f"handling a event: {event_context.name}") self.setting_context(event_context) translated_mapping = self.argument_compiler( run_body.__annotations__, @@ -366,6 +366,7 @@ def checkEventBodyAnnotations(self): async def joinMainThread(self): self.checkEventBodyAnnotations() + SessionLogger.info("session ready.") while self.shared_lock: await asyncio.sleep(0.01) else: diff --git a/test.py b/test.py index ba40014..0470c6a 100644 --- a/test.py +++ b/test.py @@ -13,7 +13,7 @@ async def event_gm(session: Session, message: MessageChain, group: Group): if message.toString().startswith("/image"): print("meow!") await session.sendGroupMessage(group, [ - #await Image.fromFileSystem("./photo_2020-02-28_16-55-34.jpg" , "group"), + await Image.fromFileSystem("./00C49FCD-D8D9-4966-B2FC-F18F6220485E.jpg" , "group"), Plain(text="??") ]) @@ -27,7 +27,6 @@ async def event_gm(session: Session, message: MessageChain, friend: Friend): Plain(text="??") ]) - print(session.enabled) await session.joinMainThread() try: