当前位置:网站首页>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")
边栏推荐
- hcip--mpls
- [Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
- IP lab, the first weekly recheck
- [secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
- 2022.02.13 - NC001. Reverse linked list
- [2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
- Summary of MySQL index failure scenarios
- All the ArrayList knowledge you want to know is here
- "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
- 根据csv文件某一列字符串中某个数字排序
猜你喜欢
2022.02.13 - NC001. Reverse linked list
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
ESP系列引脚說明圖匯總
Zhong Xuegao, who cannot be melted, cannot escape the life cycle of online celebrity products
Easy to use tcp-udp_ Debug tool download and use
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
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
好用的TCP-UDP_debug工具下载和使用
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
Sanzi chess (C language)
随机推荐
从 TiDB 集群迁移数据至另一 TiDB 集群
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
ESP系列引脚说明图汇总
升级 TiDB Operator
2.10transfrom attribute
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
灰度升级 TiDB Operator
IP lab, the first weekly recheck
C language - bit segment
Online yaml to CSV tool
LDAP Application Section (4) Jenkins Access
[research materials] 2021 Research Report on China's smart medical industry - Download attached
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
Migrate data from CSV files to tidb
PHP - Common magic method (nanny level teaching)
wincc7.5下载安装教程(Win10系统)
使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
Analysis of Top1 accuracy and top5 accuracy examples
Migrate data from SQL files to tidb
sys.argv