Skip to content

Commit

Permalink
improve: logbook log level
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenwe_i_lin committed Feb 29, 2020
1 parent 8b10a12 commit 046e9ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions mirai/logger.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions mirai/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -270,15 +270,15 @@ 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))
except Exception as e:
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__,
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="??")
])

Expand All @@ -27,7 +27,6 @@ async def event_gm(session: Session, message: MessageChain, friend: Friend):
Plain(text="??")
])

print(session.enabled)
await session.joinMainThread()

try:
Expand Down

0 comments on commit 046e9ed

Please sign in to comment.