自定義輸出格式
我們可以在之前添加的輸出格式中添加其他的格式內(nèi)容
import coloredlogs
import logging
def func_name():
# 增加了modules、funcName兩個(gè)變量,分辨標(biāo)識(shí)我們?nèi)罩舅谖募约霸谀囊粋€(gè)函數(shù)中輸入的日志
coloredlogs.install(level='DEBUG', fmt='%(asctime)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s')
logging.debug('debug message')
logging.info('info message')
logging.error('error message')
logging.warning('warning message')
func_name()
輸出結(jié)果如下
我們?cè)黾恿藘蓚€(gè)變量后,可以方便我們后續(xù)尋找問(wèn)題時(shí)就直接定位到了那個(gè)文件中的哪個(gè)函數(shù)出了問(wèn)題,這是不是就方便我們后面解決問(wèn)題的效率。
自定義日志級(jí)別輸出樣式
再上面我們是直接使用了coloredlogs中的默認(rèn)日志級(jí)別顏色樣式,同樣的我們也可以自定義設(shè)置不同日志的顯示的樣色樣式
import coloredlogs
import logging
def fun_name():
level_styles = coloredlogs.DEFAULT_LEVEL_STYLES.copy()
level_styles['debug'] = {'color': 'magenta'}
level_styles['info'] = {'color': 'yellow'}
level_styles['error'] = {'color': 'red'}
level_styles['warning'] = {'color': 'blue'}
coloredlogs.install(level="DEBUG", level_styles=level_styles,
fmt='%(asctime)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s')
logging.debug('debug message')
logging.info('info message')
logging.error('error message')
logging.warning('warning message')
fun_name()
輸入樣式如下
-
文件
+關(guān)注
關(guān)注
1文章
579瀏覽量
25358 -
日志
+關(guān)注
關(guān)注
0文章
144瀏覽量
10864 -
python
+關(guān)注
關(guān)注
56文章
4827瀏覽量
86701
發(fā)布評(píng)論請(qǐng)先 登錄
HarmonyOS應(yīng)用自定義鍵盤解決方案
ESP32下如何加自定義Python庫(kù)?
自定義Python PyPI存儲(chǔ)庫(kù)
多媒體視頻輸出格式有哪些?
Python學(xué)習(xí)要點(diǎn):自定義序列實(shí)現(xiàn)切片功能
自定義視圖組件教程案例
ArkUI如何自定義彈窗(eTS)
什么是自定義序列

自定義算子開(kāi)發(fā)

如何在TPT中使用Python實(shí)現(xiàn)自定義報(bào)告

評(píng)論