python打log_python根据文件大小打log日志
本文實例講述了python根據文件大小打log日志的方法,分享給大家供大家參考。具體方法如下:
import glob
import logging
import logging.handlers
log_filename='logging_rotatingfile_example.out'
# set up a specific logger with our desired output level
my_logger = logging.getlogger('mylogger')
my_logger.setlevel(logging.debug)
# add the log message handler to the logger
handler = logging.handlers.rotatingfilehandler(log_filename,
maxbytes=20,
backupcount=5,
)
my_logger.addhandler(handler)
# log some messages
for i in range(20):
my_logger.debug('i = %d' % i)
# see what files are created
logfiles = glob.glob('%s*' % log_filename)
for filename in logfiles:
print filename
該實例可實現循環打日志 ,第一個文件達到maxbytes大小后,就寫入第二個文件。
希望本文所述對大家的python程序設計有所幫助。
希望與廣大網友互動??
點此進行留言吧!
總結
以上是生活随笔為你收集整理的python打log_python根据文件大小打log日志的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 5.7.13 mac_Mac
- 下一篇: springboot security