当前位置:网站首页>Colorlog combined with logging to print colored logs
Colorlog combined with logging to print colored logs
2022-07-06 08:24:00 【Don't seek great wealth, just seek wealth to rival the country】
import logging
import colorlog
# log_colors={
# 'DEBUG':'cyan',
# 'INFO': 'green',
# 'WARNING':'yellow',
# 'ERROR': 'red',
# 'CRITICAL':'red,bg_white'
},
# First step : Create a log collector logger
lg=logging.getLogger(__file__)
# The second step : Modify the output level of the log
lg.setLevel(logging.DEBUG)
# Set the output channel -- Output to console
# sh=colorlog.StreamHandler()
sh1=logging.StreamHandler()
# The third step : Set the output log content format
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")
边栏推荐
- TiDB备份与恢复简介
- [t31zl intelligent video application processor data]
- IOT -- interpreting the four tier architecture of the Internet of things
- Pointer advanced --- pointer array, array pointer
- ESP系列引脚说明图汇总
- Let the bullets fly for a while
- ESP系列引脚說明圖匯總
- PLT in Matplotlib tight_ layout()
- Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
- hcip--mpls
猜你喜欢
3. File operation 3-with
2022 Inner Mongolia latest construction tower crane (construction special operation) simulation examination question bank and answers
Wireshark grabs packets to understand its word TCP segment
Hungry for 4 years + Ali for 2 years: some conclusions and Thoughts on the road of research and development
C language - bit segment
Deep learning: derivation of shallow neural networks and deep neural networks
Résumé des diagrammes de description des broches de la série ESP
【刷题】牛客网面试必刷TOP101
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
Hcip day 16
随机推荐
Remote storage access authorization
Sanzi chess (C language)
All the ArrayList knowledge you want to know is here
Restore backup data on S3 compatible storage with br
[MySQL] database stored procedure and storage function clearance tutorial (full version)
使用 TiUP 升级 TiDB
ESP系列引脚說明圖匯總
[t31zl intelligent video application processor data]
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
【MySQL】锁
Understanding of law of large numbers and central limit theorem
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
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
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
Day29-t77 & t1726-2022-02-13-don't answer by yourself
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached
[untitled]
Introduction to backup and recovery Cr
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
synchronized 解决共享带来的问题