当前位置:网站首页>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")
边栏推荐
- matplotlib. Widgets are easy to use
- leetcode刷题 (5.28) 哈希表
- MFC sends left click, double click, and right click messages to list controls
- 化不掉的钟薛高,逃不出网红产品的生命周期
- 【T31ZL智能视频应用处理器资料】
- 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
- Nft智能合约发行,盲盒,公开发售技术实战--合约篇
- 1. Color inversion, logarithmic transformation, gamma transformation source code - miniopencv from zero
- Binary tree creation & traversal
- From monomer structure to microservice architecture, introduction to microservices
猜你喜欢
Uibehavior, a comprehensive exploration of ugui source code
Circular reference of ES6 module
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
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
Go learning notes (3) basic types and statements (2)
Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
NFT smart contract release, blind box, public offering technology practice -- contract
Ruffian Heng embedded bimonthly, issue 49
Secure captcha (unsafe verification code) of DVWA range
Zhong Xuegao, who cannot be melted, cannot escape the life cycle of online celebrity products
随机推荐
Oracle time display adjustment
On why we should program for all
Configuring OSPF load sharing for Huawei devices
IoT -- 解读物联网四层架构
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
使用 Dumpling 备份 TiDB 集群数据到兼容 S3 的存储
Sanzi chess (C language)
Golang DNS write casually
A Closer Look at How Fine-tuning Changes BERT
1202 character lookup
On the day of resignation, jd.com deleted the database and ran away, and the programmer was sentenced
MFC 给列表控件发送左键单击、双击、以及右键单击消息
Summary of MySQL index failure scenarios
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
[research materials] 2021 Research Report on China's smart medical industry - Download attached
Understanding of law of large numbers and central limit theorem
Common functions for PHP to process strings
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
From monomer structure to microservice architecture, introduction to microservices
Database basic commands