欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python3.6日志Logging模塊簡(jiǎn)單用法示例

 更新時(shí)間:2018年06月14日 10:37:44   作者:Tyran_U  
這篇文章主要介紹了Python3.6日志Logging模塊簡(jiǎn)單用法,結(jié)合實(shí)例形式分析了Python3.6環(huán)境下日志Logging模塊設(shè)置格式、文件流輸出相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python3.6日志Logging模塊簡(jiǎn)單用法。分享給大家供大家參考,具體如下:

Logging是一個(gè)很方便的模塊,用來(lái)打印日志

我直接列出一個(gè)最靈活的方法

# -*- coding:utf-8 -*-
#!python3
import logging
logger = logging.getLogger() # logging對(duì)象
fh = logging.FileHandler("test.log") # 文件對(duì)象
sh = logging.StreamHandler() # 輸出流對(duì)象
fm = logging.Formatter('%(asctime)s-%(filename)s[line%(lineno)d]-%(levelname)s-%(message)s') # 格式化對(duì)象
fh.setFormatter(fm) # 設(shè)置格式
sh.setFormatter(fm) # 設(shè)置格式
logger.addHandler(fh) # logger添加文件輸出流
logger.addHandler(sh) # logger添加標(biāo)準(zhǔn)輸出流(std out)
logger.setLevel(logging.DEBUG) # 設(shè)置從那個(gè)等級(jí)開(kāi)始提示
logger.debug("debug Test")
logger.info("info Test")
logger.warning("warning Test")
logger.error("error Test")
logger.critical("critical Test")

運(yùn)行結(jié)果:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Python日志操作技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門(mén)與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論