当前位置:网站首页>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")
边栏推荐
- 好用的TCP-UDP_debug工具下载和使用
- [cloud native] teach you how to build ferry open source work order system
- NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
- Learn Arduino with examples
- [untitled]
- Synchronized solves problems caused by sharing
- C language - bit segment
- leetcode刷题 (5.31) 字符串
- [t31zl intelligent video application processor data]
- Deep learning: derivation of shallow neural networks and deep neural networks
猜你喜欢

Yyds dry goods inventory three JS source code interpretation eventdispatcher

vulnhub hackme: 1

Sanzi chess (C language)

Pointer advanced --- pointer array, array pointer

C language - bit segment

【刷题】牛客网面试必刷TOP101

让学指针变得更简单(三)

化不掉的钟薛高,逃不出网红产品的生命周期
![[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached](/img/35/898a8086bc35462b0fcb9e6b58b86b.jpg)
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
随机推荐
[t31zl intelligent video application processor data]
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
Go learning notes (3) basic types and statements (2)
化不掉的钟薛高,逃不出网红产品的生命周期
将 NFT 设置为 ENS 个人资料头像的分步指南
Make learning pointer easier (3)
logback1.3. X configuration details and Practice
Char to leading 0
From monomer structure to microservice architecture, introduction to microservices
[cloud native] teach you how to build ferry open source work order system
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
Vocabulary notes for postgraduate entrance examination (3)
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
CISP-PTE实操练习讲解
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
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
Permutation and combination function
Configuring OSPF load sharing for Huawei devices
hcip--mpls
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