当前位置:网站首页>Colorlog结合logging打印有颜色的日志
Colorlog结合logging打印有颜色的日志
2022-07-06 08:19:00 【不求大富大贵只求富可敌国】
import logging
import colorlog
# log_colors={
# 'DEBUG':'cyan',
# 'INFO': 'green',
# 'WARNING':'yellow',
# 'ERROR': 'red',
# 'CRITICAL':'red,bg_white'
},
#第一步:创建一个日志收集器logger
lg=logging.getLogger(__file__)
#第二步:修改日志的输出级别
lg.setLevel(logging.DEBUG)
#设置输出渠道--输出到控制台
# sh=colorlog.StreamHandler()
sh1=logging.StreamHandler()
#第三步:设置输出的日志内容格式
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")
边栏推荐
- File upload of DVWA range
- Remote storage access authorization
- Tidb backup and recovery introduction
- Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
- Hcip day 16
- 从 SQL 文件迁移数据到 TiDB
- 灰度升级 TiDB Operator
- leetcode刷题 (5.29) 哈希表
- 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
- 【云原生】手把手教你搭建ferry开源工单系统
猜你喜欢

Secure captcha (unsafe verification code) of DVWA range

On the day of resignation, jd.com deleted the database and ran away, and the programmer was sentenced

Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform

leetcode刷题 (5.28) 哈希表

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

matplotlib. Widgets are easy to use

2. File operation - write

Chinese Remainder Theorem (Sun Tzu theorem) principle and template code

Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation

Online yaml to CSV tool
随机推荐
Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
Data governance: data quality
[t31zl intelligent video application processor data]
Permutation and combination function
LDAP应用篇(4)Jenkins接入
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
TiDB备份与恢复简介
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
JS select all and tab bar switching, simple comments
Golang DNS 随便写写
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
好用的TCP-UDP_debug工具下载和使用
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached
Online yaml to CSV tool
Understanding of law of large numbers and central limit theorem
Entity class design for calculating age based on birthday
Huawei cloud OBS file upload and download tool class
Sanzi chess (C language)
C language - bit segment