Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SC-202112251857\Administrator committed Jan 8, 2022
1 parent ae4333a commit cd452da
Showing 7 changed files with 72 additions and 34 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@


### 屏幕流日志效果图
![Image text](https://i.niupic.com/images/2020/11/04/8WZf.png)
![Image text](https://i.ibb.co/VvSSrfq/X-X1-MW4-XJ-PRJVQ3-XZSG9-R.png)


```
@@ -30,7 +30,7 @@
```
### 屏幕流日志效果图,设置不使用背景色块。
###### 在项目根目录下自动生成的nb_log_config.py配置文件中设置DISPLAY_BACKGROUD_COLOR_IN_CONSOLE = False
[![hVoOmj.png](https://z3.ax1x.com/2021/08/25/hVoOmj.png)](https://imgtu.com/i/hVoOmj)
[![hVoOmj.png](https://s4.ax1x.com/2022/01/08/7iQGEn.md.png)](https://s4.ax1x.com/2022/01/08/7iQGEn.md.png)

### 屏幕流日志效果图,设置既不使用背景色块也不使用彩色文字

@@ -39,6 +39,9 @@
###### 在项目根目录下自动生成的nb_log_config.py配置文件中设置 DEFAULUT_USE_COLOR_HANDLER = False
[![hVTiX4.png](https://z3.ax1x.com/2021/08/25/hVTiX4.png)](https://imgtu.com/i/hVTiX4)


##### 如果不希望每次启动代码显示教你怎么设置pycharm颜色,可以设置 SHOW_PYCHARM_COLOR_SETINGS = False

```
very sharp color display,monkey patch bulitin print
and high-performance multiprocess safe roating file handler,
@@ -267,7 +270,7 @@ nb_log_config.py的内容如下,默认都是用#注释了,如果放开某项
```
如果反对日志有各种彩色,可以设置 DEFAULUT_USE_COLOR_HANDLER = False
如果反对日志有块状背景彩色,可以设置 DISPLAY_BACKGROUD_COLOR_IN_CONSOLE = False
如果想屏蔽nb_log包对怎么设置pycahrm的颜色的提示,可以设置 WARNING_PYCHARM_COLOR_SETINGS = False
如果想屏蔽nb_log包对怎么设置pycahrm的颜色的提示,可以设置 SHOW_PYCHARM_COLOR_SETINGS = False
如果想改变日志模板,可以设置 FORMATTER_KIND 参数,只带了7种模板,可以自定义添加喜欢的模板
```

6 changes: 3 additions & 3 deletions nb_log/__init__.py
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@
"""
1)使用pycharm时候,强烈建议按下面的重新自定义设置pycharm的console里面的主题颜色,否则颜色显示瞎眼,代码里面规定的颜色只是大概的红黄蓝绿。在不同的ide软件和主题、字体下是不同的显示效果,需要用户自己设置。
设置方式为 打开pycharm的 file -> settings -> Editor -> Color Scheme -> Console Colors 选择monokai,点击展开 ANSI colors,
并重新修改自定义6个颜色,设置Blue为 1585FF ,Cyan为 06B8B8 ,Green 为 05A53F ,Magenta为 ff1cd5 ,red为 FF0207 ,yellow为 FFB009
如果设置为显示背景色快,由于不同版本的pycahrm或主题,可以根据控制台实际显示设置 White 为 FFFFFF , Black 为 1F1F1F ,因为背景色是深色,前景色的文字设置为白色比黑色好
并重新修改自定义7个颜色,设置Blue为 0454F3 ,Cyan为 04DCF8 ,Green 为 13FC02 ,Magenta为 ff1cd5 ,red为 EB02F6 ,yellow为 EAFA04 ,gray 为 FFFFFF ,white 为 FFFFFF
不同版本的pycahrm或主题或ide,可以根据控制台根据实际显示设置
2)使用xshell或finashell工具连接linux也可以自定义主题颜色,默认使用shell连接工具的颜色也可以。
颜色效果如连接 https://i.niupic.com/images/2020/11/04/8WZf.png
颜色效果如连接 https://ibb.co/qRssXTr
在当前项目根目录的 nb_log_config.py 中可以修改当get_logger方法不传参时后的默认日志行为。
52 changes: 41 additions & 11 deletions nb_log/handlers.py
Original file line number Diff line number Diff line change
@@ -433,7 +433,6 @@ def __init__(self, stream=None, ):
stream = sys.stdout # stderr无彩。
self.stream = stream
self._display_method = 7 if os_name == 'posix' else 0
self._word_color = 37 if os_name == 'posix' else 37

def flush(self):
"""
@@ -451,19 +450,19 @@ def __build_color_msg_with_backgroud_color000(self, record_level, assist_msg, ef
if record_level == 10:
# msg_color = ('\033[0;32m%s\033[0m' % msg) # 绿色
# print(msg1)
msg_color = f'\033[0;32m{assist_msg}\033[0m \033[0;{self._word_color};42m{effective_information_msg}\033[0m' # 绿色
msg_color = f'\033[0;32m{assist_msg}\033[0m \033[0;37;42m{effective_information_msg}\033[0m' # 绿色
elif record_level == 20:
# msg_color = ('\033[%s;%sm%s\033[0m' % (self._display_method, self.bule, msg)) # 青蓝色 36 96
msg_color = f'\033[0;36m{assist_msg}\033[0m \033[0;{self._word_color};46m{effective_information_msg}\033[0m'
msg_color = f'\033[0;36m{assist_msg}\033[0m \033[0;37;46m{effective_information_msg}\033[0m'
elif record_level == 30:
# msg_color = ('\033[%s;%sm%s\033[0m' % (self._display_method, self.yellow, msg))
msg_color = f'\033[0;33m{assist_msg}\033[0m \033[0;{self._word_color};43m{effective_information_msg}\033[0m'
msg_color = f'\033[0;33m{assist_msg}\033[0m \033[0;37;43m{effective_information_msg}\033[0m'
elif record_level == 40:
# msg_color = ('\033[%s;35m%s\033[0m' % (self._display_method, msg)) # 紫红色
msg_color = f'\033[0;35m{assist_msg}\033[0m \033[0;{self._word_color};45m{effective_information_msg}\033[0m'
msg_color = f'\033[0;35m{assist_msg}\033[0m \033[0;37;45m{effective_information_msg}\033[0m'
elif record_level == 50:
# msg_color = ('\033[%s;31m%s\033[0m' % (self._display_method, msg)) # 血红色
msg_color = f'\033[0;31m{assist_msg}\033[0m \033[0;{self._word_color};41m{effective_information_msg}\033[0m'
msg_color = f'\033[0;31m{assist_msg}\033[0m \033[0;37;41m{effective_information_msg}\033[0m'
else:
msg_color = f'{assist_msg} {effective_information_msg}'
return msg_color
@@ -495,19 +494,19 @@ def __build_color_msg_with_backgroud_color(self, record_level, record_copy: logg
background_color = ''
complete_color = ''
if record_level == 10:
background_color = f'[0;{self._word_color};42m'
background_color = f'[0;30;42m'
complete_color = f'[0;32m'
elif record_level == 20:
background_color = f'[0;{self._word_color};46m'
background_color = f'[0;30;46m'
complete_color = f'[0;36m'
elif record_level == 30:
background_color = f'[0;{self._word_color};43m'
background_color = f'[0;30;43m'
complete_color = f'[0;33m'
elif record_level == 40:
background_color = f'[0;{self._word_color};45m'
background_color = f'[0;37;45m'
complete_color = f'[0;35m'
elif record_level == 50:
background_color = f'[0;{self._word_color};41m'
background_color = f'[0;37;41m'
complete_color = f'[0;31m'
record_copy.msg = f'\033{background_color}{record_copy.msg}\033[0m'
msg_color_without = self.format(record_copy)
@@ -519,6 +518,35 @@ def __build_color_msg_with_backgroud_color(self, record_level, record_copy: logg
# print(repr(msg_color))
return msg_color

def __build_color_msg_with_backgroud_color3333(self, record_level, record_copy: logging.LogRecord, ):
background_color = ''
complete_color = ''
if record_level == 10:
background_color = f'[0;30;42m'
complete_color = f'[0;32m'
elif record_level == 20:
background_color = f'[0;30;46m'
complete_color = f'[0;36m'
elif record_level == 30:
background_color = f'[0;30;43m'
complete_color = f'[0;33m'
elif record_level == 40:
background_color = f'[0;37;45m'
complete_color = f'[0;35m'
elif record_level == 50:
background_color = f'[0;37;41m'
complete_color = f'[0;31m'
record_copy.msg = f'\033{complete_color}{record_copy.msg}\033[0m'
msg_color_without = self.format(record_copy)
# print(repr(msg_color))
if isinstance(self.formatter, JsonFormatter) and background_color: # json会把/033 转义成\u001b,导致颜色显示不出来。
msg_color_without = msg_color_without.replace(rf'\u001b{background_color}', f'\033{background_color}')
msg_color_without = msg_color_without.replace(r'\u001b[0m', f'\033[0m\033{complete_color}')
# msg_color = f'\033{complete_color}{msg_color_without}\033[0m'
msg_color = f'\033{background_color}{msg_color_without}\033[0m'
# print(repr(msg_color))
return msg_color

def __build_color_msg_with_no_backgroud_color(self, record_level, record_copy: logging.LogRecord, ):
complete_msg = self.format(record_copy)
if record_level == 10:
@@ -703,8 +731,10 @@ def rollover_and_do_write(self, ):
with self.__lock_for_rotate:
self._rollover_and_do_write()


ConcurrentRotatingFileHandlerWithBufferInitiativeLinux = ConcurrentRotatingFileHandler


class CompatibleSMTPSSLHandler(handlers.SMTPHandler):
"""
官方的SMTPHandler不支持SMTP_SSL的邮箱,这个可以两个都支持,并且支持邮件发送频率限制
2 changes: 1 addition & 1 deletion nb_log/monkey_print.py
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ def nb_print(*args, sep=' ', end='\n', file=None, flush=True):
f'\033[0;34m{time.strftime("%H:%M:%S")} "{file_name}:{line}" \033[0;{WORD_COLOR};44m{sep.join(args)}\033[0m{end} \033[0m') # 36 93 96 94
else:
stdout_write(
f'\033[0;{WORD_COLOR}34m{time.strftime("%H:%M:%S")} "{file_name}:{line}" {sep.join(args)} {end} \033[0m') # 36 93 96 94
f'\033[0;{WORD_COLOR};34m{time.strftime("%H:%M:%S")} "{file_name}:{line}" {sep.join(args)} {end} \033[0m') # 36 93 96 94
# sys.stdout.write(f'\033[0;30;44m"{file_name}:{line}" {time.strftime("%H:%M:%S")} {"".join(args)}\033[0m\n')
else:
stdout_write(
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@

setup(
name='nb_log', #
version="7.1",
version="7.2",
description=(
'very sharp color display,monkey patch bulitin print and high-performance multiprocess safe roating file handler,other handlers includeing dintalk ,email,kafka,elastic and so on '
),
@@ -66,7 +66,7 @@
python setup.py sdist & twine upload dist/nb_log-6.0.tar.gz
python setup.py sdist ; python -m twine upload dist/nb_log-7.1.tar.gz
python setup.py sdist & python -m twine upload dist/nb_log-7.2.tar.gz
twine upload dist/*
3 changes: 2 additions & 1 deletion tests/example.py
Original file line number Diff line number Diff line change
@@ -18,4 +18,5 @@



# raise(1)
# raise(1)

30 changes: 17 additions & 13 deletions tests/test6.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from nb_log import get_logger,LogManager
import requests
# from nb_log import get_logger,LogManager
# import requests
#
# get_logger('urllib3')
# requests.get("http://www.baidu.com")
#
#
# LogManager('abcd').preset_log_level(20)
# l1 = get_logger('abcd',log_level_int=20)
# l2 = get_logger('abcd',log_level_int=30)
#
#
# l1.debug('能显示不?')
#
# l1.info('能显示不?')

get_logger('urllib3')
requests.get("http://www.baidu.com")
import time


LogManager('abcd').preset_log_level(20)
l1 = get_logger('abcd',log_level_int=20)
l2 = get_logger('abcd',log_level_int=30)


l1.debug('能显示不?')

l1.info('能显示不?')
print(f'''\033[0;34m 前缀 \033[0;37;44mdfdsffdsf\033[0m ''')

0 comments on commit cd452da

Please sign in to comment.