当前位置:网站首页>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")
边栏推荐
- 让学指针变得更简单(三)
- Nacos Development Manual
- Golang DNS 随便写写
- 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
- It's hard to find a job when the industry is in recession
- 指针和数组笔试题解析
- Yu Xia looks at win system kernel -- message mechanism
- 【云原生】手把手教你搭建ferry开源工单系统
- 24. Query table data (basic)
- Webrtc series-h.264 estimated bit rate calculation
猜你喜欢
Golang DNS 随便写写
Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
Make learning pointer easier (3)
Circular reference of ES6 module
[untitled]
Sanzi chess (C language)
08- [istio] istio gateway, virtual service and the relationship between them
"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa
24. Query table data (basic)
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
随机推荐
Grayscale upgrade tidb operator
Migrate data from SQL files to tidb
Learn Arduino with examples
[Yugong series] February 2022 U3D full stack class 010 prefabricated parts
【云原生】手把手教你搭建ferry开源工单系统
从 CSV 文件迁移数据到 TiDB
logback1.3. X configuration details and Practice
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
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
化不掉的钟薛高,逃不出网红产品的生命周期
JS select all and tab bar switching, simple comments
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
Asia Pacific Financial Media | designer universe | Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers
Data governance: misunderstanding sorting
Flash return file download
ESP系列引脚说明图汇总
Wincc7.5 download and installation tutorial (win10 system)
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
From monomer structure to microservice architecture, introduction to microservices
Huawei cloud OBS file upload and download tool class