From 5933bb498fc60f33cc76b46c99ba4417ccbcb3fd Mon Sep 17 00:00:00 2001 From: liuxinwei Date: Thu, 21 Mar 2024 22:42:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E5=AF=8C?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/d2py/utils/log_config.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/d2py/utils/log_config.py b/src/d2py/utils/log_config.py index 503d466f..cbebfb88 100644 --- a/src/d2py/utils/log_config.py +++ b/src/d2py/utils/log_config.py @@ -13,6 +13,7 @@ def config_logging( }, file_formatter: str="%(levelname)s|%(asctime)s|%(name)s| -> %(message)s\n|==>%(module)s.%(funcName)s@: %(pathname)s:%(lineno)d", stream_formatter: str="%(levelname)s|%(asctime)s|%(name)s| -> %(message)s", + rich_kwargs: dict|None=None, **kwargs): """配置 logging @@ -24,6 +25,12 @@ def config_logging( default_filter_mod_names: 默认过滤日志 debug 模式对应的模块名称列表 file_formatter: 日志文件配置 stream_formatter: 控制台打印配置 + rich_kwargs: 富文本模式,可为空 + 即开启如下模式 + ``` + >>> from rich.logging import RichHandler + >>> ch = RichHandler(**rich_kwargs) + ``` """ logging.basicConfig(level=logging.DEBUG, format=file_formatter, @@ -37,8 +44,13 @@ def config_logging( _logger.setLevel(logging.WARNING) # 创建日志级别更高的控制台处理程序 - ch = logging.StreamHandler() + if rich_kwargs: + from rich.logging import RichHandler + ch = RichHandler(**rich_kwargs) + else: + ch = logging.StreamHandler() ch.setLevel(logging.INFO) # 或者 logging.ERROR ch_formatter = logging.Formatter(stream_formatter) ch.setFormatter(ch_formatter) logging.getLogger("").addHandler(ch) + \ No newline at end of file