当前位置:网站首页>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")
边栏推荐
- wincc7.5下载安装教程(Win10系统)
- 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
- 使用 Dumpling 备份 TiDB 集群数据到兼容 S3 的存储
- ESP系列引脚說明圖匯總
- 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
- IOT -- interpreting the four tier architecture of the Internet of things
- 2022 Inner Mongolia latest construction tower crane (construction special operation) simulation examination question bank and answers
- Day29-t77 & t1726-2022-02-13-don't answer by yourself
- 好用的TCP-UDP_debug工具下载和使用
- NFT smart contract release, blind box, public offering technology practice -- contract
猜你喜欢

2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers

IoT -- 解读物联网四层架构

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

IOT -- interpreting the four tier architecture of the Internet of things

2022.02.13 - NC004. Print number of loops

面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读

matplotlib. Widgets are easy to use

PLT in Matplotlib tight_ layout()

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

指针和数组笔试题解析
随机推荐
Restore backup data on S3 compatible storage with br
VMware 虚拟化集群
Sanzi chess (C language)
Hill sort c language
PHP - Common magic method (nanny level teaching)
Use Alibaba icon in uniapp
Synchronized solves problems caused by sharing
[untitled]
leetcode刷题 (5.28) 哈希表
Golang DNS 随便写写
Summary of MySQL index failure scenarios
Circular reference of ES6 module
Nacos Development Manual
Migrate data from CSV files to tidb
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached
Upgrade tidb operator
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
Analysis of pointer and array written test questions
CAD ARX 获取当前的视口设置
Permutation and combination function