🎨 设置 loggermarkup 默认为 False

This commit is contained in:
Karako 2022-09-08 12:57:22 +08:00
parent 1583831b0d
commit 97a22a035b
No known key found for this signature in database
GPG Key ID: 5920831B0095D4A0
4 changed files with 29 additions and 17 deletions

View File

@ -15,16 +15,16 @@ class AioBrowser(Service):
async def start(self):
if self._playwright is None:
logger.info("正在尝试启动 [blue]Playwright[/]")
logger.info("正在尝试启动 [blue]Playwright[/]", extra={'markup': True})
self._playwright = await async_playwright().start()
logger.success("[blue]Playwright[/] 启动成功")
logger.success("[blue]Playwright[/] 启动成功", extra={'markup': True})
if self.browser is None:
logger.info("正在尝试启动 [blue]Browser[/]")
logger.info("正在尝试启动 [blue]Browser[/]", extra={'markup': True})
try:
self.browser = await self._playwright.chromium.launch(timeout=5000)
logger.success("[blue]Browser[/] 启动成功")
logger.success("[blue]Browser[/] 启动成功", extra={'markup': True})
except TimeoutError as err:
logger.warning("[blue]Browser[/] 启动失败")
logger.warning("[blue]Browser[/] 启动失败", extra={'markup': True})
raise err
return self.browser

View File

@ -22,21 +22,21 @@ class RedisDB(Service):
async def ping(self):
if await self.client.ping():
logger.info("连接 [red]Redis[/] 成功")
logger.info("连接 [red]Redis[/] 成功", extra={'markup': True})
else:
logger.info("连接 [red]Redis[/] 失败")
raise RuntimeError("连接 [red]Redis[/] 失败")
logger.info("连接 [red]Redis[/] 失败", extra={'markup': True})
raise RuntimeError("连接 Redis 失败")
async def start(self): # pylint: disable=W0221
if self._loop is None:
self._loop = asyncio.get_running_loop()
logger.info("正在尝试建立与 [red]Redis[/] 连接")
logger.info("正在尝试建立与 [red]Redis[/] 连接", extra={'markup': True})
try:
await self.ping()
except (KeyboardInterrupt, SystemExit):
pass
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()
await self.ping()

View File

@ -73,7 +73,10 @@ class Bot:
try:
import_module(pkg) # 导入插件
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 # 如有错误则继续
callback_dict: Dict[int, List[Callable]] = {}
for plugin_cls in {*Plugin.__subclasses__(), *Plugin.Conversation.__subclasses__()}:
@ -103,7 +106,10 @@ class Bot:
logger.debug(f'插件 "{path}" 添加了 {len(jobs)} 个任务')
logger.success(f'插件 "{path}" 载入成功')
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:
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
))
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):
@ -125,7 +132,10 @@ class Bot:
try:
import_module(pkg)
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
for base_service_cls in Service.__subclasses__():
try:
@ -149,7 +159,10 @@ class Bot:
try:
import_module(pkg)
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
async def stop_services(self):
@ -193,7 +206,7 @@ class Bot:
self.app.run_polling(close_loop=False)
break
except TimedOut:
logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试")
logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试", extra={'markup': True})
continue
except NetworkError as e:
logger.exception()

View File

@ -279,7 +279,6 @@ class Handler(DefaultRichHandler):
self.console = log_console
self.rich_tracebacks = True
self.tracebacks_show_locals = True
self.markup = True
self.keywords = [*self.KEYWORDS, 'BOT']
def render(