python logger簡單使用
import logging
# 1.顯示建立
logging.basicconfig(filename=
'logger.log'
,format
='%(asctime)s - %(levelname)s - %(message)s'
,level=logging.info)
# 2.定義logger,設定setlevel,filehandler,setformatter
logger = logging.getlogger(__name__)
#定義一次就可以,其他地方需要呼叫logger,只需要直接使用logger就行了
logger.setlevel(level=logging.info)
#定義過濾級別
filehandler = logging.filehandler(
"log.txt"
)# handler用於將日誌記錄傳送至合適的目的地,如檔案、終端等
filehandler.setlevel(logging.info)
formatter = logging.formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
) filehandler.setformatter(formatter)
console = logging.streamhandler(
)#日誌資訊顯示在終端terminal
console.setlevel(logging.info)
console.setformatter(formatter)
logger.addhandler(filehandler)
logger.addhandler(console)
logger.info(
"start log"
) logger.debug(
"do something"
) logger.warning(
"something fail."
) logger.info(
"finish"
)def
fun():
logger.info(
'....'
)if __name__==
'__main__'
:for i in
range(10
):logger.info(
'step {}'
.format
(i))
func(
)
python logger日誌工具類
pytest命令列執行預設不會列印log資訊,需要加 s 引數或者 capture no 即pytest s usr bin env python coding utf 8 import logging,os class logger def init self,path,clevel loggin...
SpringBoot Swagger簡單使用
io.springfox springfox swagger2 2.9.2 io.springfox springfox swagger ui 2.9.2 import org.springframework.context.annotation.bean import org.springfram...
UICollectionView的簡單使用
所屬controller要遵循三個協議 uicollectionviewdatasource,uicollectionviewdelegate,uicollectionviewdelegateflowlayout uicollectionviewflowlayout flowlayout uicol...