Fix | 顺带把所有 color formatter 的崩溃问题修复了

This commit is contained in:
shenjack 2023-11-26 23:58:57 +08:00
parent 43eb2a32e7
commit e511baa344
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 27 additions and 11 deletions

View File

@ -6,7 +6,7 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif
## Information/信息
- Version / 版本: 0.2.0
- Version / 版本: 0.2.1
- Author / 作者: shenjackyuanjie <3695888@qq.com>
> [shenjackyuanjie](https://github.com/shenjackyuanjie)
@ -30,7 +30,7 @@ pip install lib-not-dr[nuitka]
### Logger
> WIP
> 等待 0.2.0
> 等待 0.3.0
```python title="logger.py"
from lib_not_dr.logger.logger import Logger

View File

@ -1,5 +1,17 @@
# Change log / 更新日志
## 0.2.1
### Fix
- `Logger`
- `MainFormatter`
- 修复了会导致 `ColorFormatter` 崩溃的问题
## 0.2.0
> 内容和 0.2.0-rc.10 相同
## 0.2.0-rc.10
### lndl-nuitka

View File

@ -88,6 +88,7 @@ class LevelColorFormatter(BaseColorFormatter):
# 添加颜色
if color == '' or color == RESET_COLOR:
return message
if 'level' in message[1]:
message[1]['level'] = f'{color}{message[1]["level"]}{RESET_COLOR}'
return message
@ -126,8 +127,9 @@ class LoggerColorFormatter(BaseColorFormatter):
# 添加颜色
if color == '' or color == RESET_COLOR:
return message
if 'logger_name' in message[1]:
message[1]['logger_name'] = f'{color}{message[1]["logger_name"]}{RESET_COLOR}'
if message[1].get('logger_tag') is not None and message[1].get('logger_tag') != ' ':
if 'logger_tag' in message[1] and message[1].get('logger_tag') != ' ':
message[1]['logger_tag'] = f'{color}{message[1]["logger_tag"]}{RESET_COLOR}'
return message
@ -166,6 +168,7 @@ class TimeColorFormatter(BaseColorFormatter):
# 添加颜色
if color == '' or color == RESET_COLOR:
return message
if 'log_time' in message[1]:
message[1]['log_time'] = f'{color}{message[1]["log_time"]}{RESET_COLOR}'
return message
@ -210,7 +213,7 @@ class TraceColorFormatter(BaseColorFormatter):
if color == '' or color == RESET_COLOR:
return message
for name in ('log_source', 'log_line', 'log_function'):
if message[1].get(name) is not None:
if name in message[1]:
message[1][name] = f'{color}{message[1][name]}{RESET_COLOR}'
return message
@ -249,6 +252,7 @@ class MessageColorFormatter(BaseColorFormatter):
# 添加颜色
if color == '' or color == RESET_COLOR:
return message
if 'messages' in message[1]:
if message[1]['messages'][-1] == '\n':
message[1]['messages'] = f'{color}{message[1]["messages"][:-1]}{RESET_COLOR}\n'
else: