mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-25 18:04:00 +00:00
🎨 设置 logger
的 markup
默认为 False
This commit is contained in:
parent
1583831b0d
commit
97a22a035b
@ -15,16 +15,16 @@ class AioBrowser(Service):
|
|||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
if self._playwright is None:
|
if self._playwright is None:
|
||||||
logger.info("正在尝试启动 [blue]Playwright[/]")
|
logger.info("正在尝试启动 [blue]Playwright[/]", extra={'markup': True})
|
||||||
self._playwright = await async_playwright().start()
|
self._playwright = await async_playwright().start()
|
||||||
logger.success("[blue]Playwright[/] 启动成功")
|
logger.success("[blue]Playwright[/] 启动成功", extra={'markup': True})
|
||||||
if self.browser is None:
|
if self.browser is None:
|
||||||
logger.info("正在尝试启动 [blue]Browser[/]")
|
logger.info("正在尝试启动 [blue]Browser[/]", extra={'markup': True})
|
||||||
try:
|
try:
|
||||||
self.browser = await self._playwright.chromium.launch(timeout=5000)
|
self.browser = await self._playwright.chromium.launch(timeout=5000)
|
||||||
logger.success("[blue]Browser[/] 启动成功")
|
logger.success("[blue]Browser[/] 启动成功", extra={'markup': True})
|
||||||
except TimeoutError as err:
|
except TimeoutError as err:
|
||||||
logger.warning("[blue]Browser[/] 启动失败")
|
logger.warning("[blue]Browser[/] 启动失败", extra={'markup': True})
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
return self.browser
|
return self.browser
|
||||||
|
@ -22,21 +22,21 @@ class RedisDB(Service):
|
|||||||
|
|
||||||
async def ping(self):
|
async def ping(self):
|
||||||
if await self.client.ping():
|
if await self.client.ping():
|
||||||
logger.info("连接 [red]Redis[/] 成功")
|
logger.info("连接 [red]Redis[/] 成功", extra={'markup': True})
|
||||||
else:
|
else:
|
||||||
logger.info("连接 [red]Redis[/] 失败")
|
logger.info("连接 [red]Redis[/] 失败", extra={'markup': True})
|
||||||
raise RuntimeError("连接 [red]Redis[/] 失败")
|
raise RuntimeError("连接 Redis 失败")
|
||||||
|
|
||||||
async def start(self): # pylint: disable=W0221
|
async def start(self): # pylint: disable=W0221
|
||||||
if self._loop is None:
|
if self._loop is None:
|
||||||
self._loop = asyncio.get_running_loop()
|
self._loop = asyncio.get_running_loop()
|
||||||
logger.info("正在尝试建立与 [red]Redis[/] 连接")
|
logger.info("正在尝试建立与 [red]Redis[/] 连接", extra={'markup': True})
|
||||||
try:
|
try:
|
||||||
await self.ping()
|
await self.ping()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
pass
|
pass
|
||||||
except BaseException as exc:
|
except BaseException as exc:
|
||||||
logger.warning("尝试连接 [red]Redis[/] 失败,使用 [red]fakeredis[/] 模拟", exc)
|
logger.warning("尝试连接 [red]Redis[/] 失败,使用 [red]fakeredis[/] 模拟", exc, extra={'markup': True})
|
||||||
self.client = fakeredis.aioredis.FakeRedis()
|
self.client = fakeredis.aioredis.FakeRedis()
|
||||||
await self.ping()
|
await self.ping()
|
||||||
|
|
||||||
|
25
core/bot.py
25
core/bot.py
@ -73,7 +73,10 @@ class Bot:
|
|||||||
try:
|
try:
|
||||||
import_module(pkg) # 导入插件
|
import_module(pkg) # 导入插件
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
logger.exception(f'在导入文件 "{pkg}" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]')
|
logger.exception(
|
||||||
|
f'在导入文件 "{pkg}" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]',
|
||||||
|
extra={'markup': True}
|
||||||
|
)
|
||||||
continue # 如有错误则继续
|
continue # 如有错误则继续
|
||||||
callback_dict: Dict[int, List[Callable]] = {}
|
callback_dict: Dict[int, List[Callable]] = {}
|
||||||
for plugin_cls in {*Plugin.__subclasses__(), *Plugin.Conversation.__subclasses__()}:
|
for plugin_cls in {*Plugin.__subclasses__(), *Plugin.Conversation.__subclasses__()}:
|
||||||
@ -103,7 +106,10 @@ class Bot:
|
|||||||
logger.debug(f'插件 "{path}" 添加了 {len(jobs)} 个任务')
|
logger.debug(f'插件 "{path}" 添加了 {len(jobs)} 个任务')
|
||||||
logger.success(f'插件 "{path}" 载入成功')
|
logger.success(f'插件 "{path}" 载入成功')
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
logger.exception(f'在安装插件 \"{path}\" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]')
|
logger.exception(
|
||||||
|
f'在安装插件 \"{path}\" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]',
|
||||||
|
extra={'markup': True}
|
||||||
|
)
|
||||||
if callback_dict:
|
if callback_dict:
|
||||||
num = sum(len(callback_dict[i]) for i in callback_dict)
|
num = sum(len(callback_dict[i]) for i in callback_dict)
|
||||||
|
|
||||||
@ -117,7 +123,8 @@ class Bot:
|
|||||||
callback=_new_chat_member_callback, filters=StatusUpdate.NEW_CHAT_MEMBERS, block=False
|
callback=_new_chat_member_callback, filters=StatusUpdate.NEW_CHAT_MEMBERS, block=False
|
||||||
))
|
))
|
||||||
logger.success(
|
logger.success(
|
||||||
f'成功添加了 {num} 个针对 [blue]{StatusUpdate.NEW_CHAT_MEMBERS}[/] 的 [blue]MessageHandler[/]'
|
f'成功添加了 {num} 个针对 [blue]{StatusUpdate.NEW_CHAT_MEMBERS}[/] 的 [blue]MessageHandler[/]',
|
||||||
|
extra={'markup': True}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _start_base_services(self):
|
async def _start_base_services(self):
|
||||||
@ -125,7 +132,10 @@ class Bot:
|
|||||||
try:
|
try:
|
||||||
import_module(pkg)
|
import_module(pkg)
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
logger.exception(f'在导入文件 "{pkg}" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]')
|
logger.exception(
|
||||||
|
f'在导入文件 "{pkg}" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]',
|
||||||
|
extra={'markup': True}
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
for base_service_cls in Service.__subclasses__():
|
for base_service_cls in Service.__subclasses__():
|
||||||
try:
|
try:
|
||||||
@ -149,7 +159,10 @@ class Bot:
|
|||||||
try:
|
try:
|
||||||
import_module(pkg)
|
import_module(pkg)
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
logger.exception(f'在导入文件 "{pkg}" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]')
|
logger.exception(
|
||||||
|
f'在导入文件 "{pkg}" 的过程中遇到了错误: \n[red bold]{type(e).__name__}: {e}[/]',
|
||||||
|
extra={'markup': True}
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
async def stop_services(self):
|
async def stop_services(self):
|
||||||
@ -193,7 +206,7 @@ class Bot:
|
|||||||
self.app.run_polling(close_loop=False)
|
self.app.run_polling(close_loop=False)
|
||||||
break
|
break
|
||||||
except TimedOut:
|
except TimedOut:
|
||||||
logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试")
|
logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试", extra={'markup': True})
|
||||||
continue
|
continue
|
||||||
except NetworkError as e:
|
except NetworkError as e:
|
||||||
logger.exception()
|
logger.exception()
|
||||||
|
@ -279,7 +279,6 @@ class Handler(DefaultRichHandler):
|
|||||||
self.console = log_console
|
self.console = log_console
|
||||||
self.rich_tracebacks = True
|
self.rich_tracebacks = True
|
||||||
self.tracebacks_show_locals = True
|
self.tracebacks_show_locals = True
|
||||||
self.markup = True
|
|
||||||
self.keywords = [*self.KEYWORDS, 'BOT']
|
self.keywords = [*self.KEYWORDS, 'BOT']
|
||||||
|
|
||||||
def render(
|
def render(
|
||||||
|
Loading…
Reference in New Issue
Block a user