当前位置:网站首页>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")
边栏推荐
- What are the ways to download network pictures with PHP
- flask返回文件下载
- 23. Update data
- [research materials] 2021 live broadcast annual data report of e-commerce - Download attached
- leetcode刷题 (5.31) 字符串
- What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
- [Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
- Wireshark grabs packets to understand its word TCP segment
- 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
- Introduction to backup and recovery Cr
猜你喜欢

matplotlib. Widgets are easy to use

Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio

A Closer Look at How Fine-tuning Changes BERT

2. File operation - write

"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media

From monomer structure to microservice architecture, introduction to microservices

Golang DNS 随便写写
![08- [istio] istio gateway, virtual service and the relationship between them](/img/fb/09793f5fd12c2906b73cc42722165f.jpg)
08- [istio] istio gateway, virtual service and the relationship between them

What is the use of entering the critical point? How to realize STM32 single chip microcomputer?

2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
随机推荐
hcip--mpls
Binary tree creation & traversal
wincc7.5下载安装教程(Win10系统)
3. File operation 3-with
leetcode刷题 (5.29) 哈希表
备份与恢复 CR 介绍
Summary of MySQL index failure scenarios
Tidb backup and recovery introduction
Online yaml to CSV tool
Online yaml to CSV tool
【T31ZL智能视频应用处理器资料】
Restore backup data on S3 compatible storage with br
Secure captcha (unsafe verification code) of DVWA range
Pyqt5 development tips - obtain Manhattan distance between coordinates
The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
flask返回文件下载
让学指针变得更简单(三)
MFC sends left click, double click, and right click messages to list controls
【云原生】手把手教你搭建ferry开源工单系统
Easy to use tcp-udp_ Debug tool download and use