亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

出來的時候,縮進怎麼有問題了?該怎么改?

出來的時候,縮進怎麼有問題了?該怎么改?

慕妹3146593 2023-03-18 17:13:29
logging.conf:---------------------------# logging.conf[loggers]keys=root,test,test2[handlers]keys=consoleHandler,rotateFileHandler[formatters]keys=simpleFormatter[formatter_simpleFormatter]format=[%(asctime)s](%(levelname)s)%(name)s : %(message)s[logger_root]level=DEBUGhandlers=consoleHandler,rotateFileHandler[logger_test]level=DEBUGhandlers=consoleHandler,rotateFileHandlerqualname=testpropagate=0[logger_test2]level=DEBUGhandlers=consoleHandler,rotateFileHandlerqualname=test2propagate=0[handler_consoleHandler]class=StreamHandlerlevel=DEBUGformatter=simpleFormatterargs=(sys.stdout,)[handler_rotateFileHandler]class=handlers.RotatingFileHandlerlevel=DEBUGformatter=simpleFormatterargs=('test.log', 'a', 20000, 9)----------------------------------------------my_test:----------------------------------------------#python33from tkinter import *import logging import logging.configdef Log(text):logging.config.fileConfig("logging.conf")logger = loggong.getLogger("test")logger.info(text)def Test():Log("Test")if __name__=="__main__":root = Tk()btn1 = Button(root, text='test', command=Test)btn1.grid()root.mainloop()
查看完整描述

1 回答

?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

原生loggging類+  TimedRotatingFileHandler類 實現按day hour second 切分import loggingfrom logging.handlers import TimedRotatingFileHandlerlog = logging.getLogger(loggerName)formatter = logging.Formatter('%(name)-12s %(asctime)s level-%(levelname)-8s thread-%(thread)-8d %(message)s')   # 每行日志的前綴設置fileTimeHandler = TimedRotatingFileHandler(BASIC_LOG_PATH + filename, "S"110)fileTimeHandler.suffix = "%Y%m%d.log"  #設置 切分后日志文件名的時間格式 默認 filename+"." + suffix 如果需要更改需要改logging 源碼fileTimeHandler.setFormatter(formatter)logging.basicConfig(level = logging.INFO)fileTimeHandler.setFormatter(formatter)log.addHandler(fileTimeHandler)try:    log.error(msg)except Exception, e:    print "writeLog error"finally:   log.removeHandler(fileTimeHandler)

值 interval的類型
S 秒
M 分鐘
H 小時
D 天
W 周
midnight 在午夜


查看完整回答
反對 回復 2023-03-21
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號