当前位置:网站首页>Colorlog结合logging打印有颜色的日志
Colorlog结合logging打印有颜色的日志
2022-07-06 08:19:00 【不求大富大贵只求富可敌国】
import logging
import colorlog
# log_colors={
# 'DEBUG':'cyan',
# 'INFO': 'green',
# 'WARNING':'yellow',
# 'ERROR': 'red',
# 'CRITICAL':'red,bg_white'
},
#第一步:创建一个日志收集器logger
lg=logging.getLogger(__file__)
#第二步:修改日志的输出级别
lg.setLevel(logging.DEBUG)
#设置输出渠道--输出到控制台
# sh=colorlog.StreamHandler()
sh1=logging.StreamHandler()
#第三步:设置输出的日志内容格式
fh=logging.FileHandler(r"C:\Users\jam96\PycharmProjects\all_module\logging_test\data\jxd.log",encoding="utf-8")
lg.addHandler(sh1)
lg.addHandler(fh)
#%(log_color)s
cl=colorlog.ColoredFormatter(fmt="**%(log_color)s** %(asctime)s %(pathname)s %(funcName)s [%(lineno)d] %(levelname)s %(message)s")
fm=logging.Formatter("%(asctime)s %(pathname)s %(funcName)s [%(lineno)d] %(levelname)s %(message)s")
sh1.setFormatter(cl)
fh.setFormatter(fm)
if __name__ == '__main__':
for i in range(10):
lg.debug("12345")
lg.info("abcde")
lg.warning("******")
lg.error("good boy")
lg.critical("bad girl")
边栏推荐
- 3. File operation 3-with
- What are the ways to download network pictures with PHP
- C language custom type: struct
- Migrate data from SQL files to tidb
- How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
- [secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
- Data governance: misunderstanding sorting
- Ruffian Heng embedded bimonthly, issue 49
- Char to leading 0
- Yyds dry goods inventory three JS source code interpretation eventdispatcher
猜你喜欢

C语言 - 位段

C language custom type: struct

The Vice Minister of the Ministry of industry and information technology of "APEC industry +" of the national economic and information technology center led a team to Sichuan to investigate the operat

synchronized 解决共享带来的问题

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

2.10transfrom attribute

hcip--mpls

Online yaml to CSV tool
![[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]](/img/ae/4e616882f6d68acdf8e885843e68a3.jpg)
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]

File upload of DVWA range
随机推荐
Learn Arduino with examples
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Analysis of Top1 accuracy and top5 accuracy examples
Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
Leetcode question brushing record | 203_ Remove linked list elements
好用的TCP-UDP_debug工具下载和使用
Grayscale upgrade tidb operator
Hill sort c language
Fibonacci sequence
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Go learning notes (3) basic types and statements (2)
Webrtc series-h.264 estimated bit rate calculation
A Closer Look at How Fine-tuning Changes BERT
使用 TiUP 升级 TiDB
Analysis of pointer and array written test questions
Yu Xia looks at win system kernel -- message mechanism
Uibehavior, a comprehensive exploration of ugui source code
Hungry for 4 years + Ali for 2 years: some conclusions and Thoughts on the road of research and development
华为云OBS文件上传下载工具类
Use br to back up tidb cluster data to S3 compatible storage