当前位置:网站首页>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")
边栏推荐
- PHP - Common magic method (nanny level teaching)
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
- It's hard to find a job when the industry is in recession
- Step by step guide to setting NFT as an ens profile Avatar
- Circular reference of ES6 module
- Huawei cloud OBS file upload and download tool class
- Erc20 token agreement
- Use Alibaba icon in uniapp
- Golang DNS 随便写写
猜你喜欢
C language - bit segment
IOT -- interpreting the four tier architecture of the Internet of things
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
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
Let the bullets fly for a while
在 uniapp 中使用阿里图标
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
2022.02.13 - NC001. Reverse linked list
"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
随机推荐
Let the bullets fly for a while
指针进阶---指针数组,数组指针
从 CSV 文件迁移数据到 TiDB
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
[Yugong series] February 2022 U3D full stack class 010 prefabricated parts
Easy to use tcp-udp_ Debug tool download and use
2022.02.13 - NC001. Reverse linked list
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
Huawei cloud OBS file upload and download tool class
1204 character deletion operation (2)
From monomer structure to microservice architecture, introduction to microservices
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
3. File operation 3-with
C语言 - 位段
让学指针变得更简单(三)
PHP - Common magic method (nanny level teaching)
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
CISP-PTE实操练习讲解