首页 > 编程语言 > 详细

python根据文件大小打log日志

时间:2016-01-16 08:47:41      阅读:286      评论:0      收藏:0      [点我收藏+]

本文实例讲述了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日志

原文:http://www.jb51.net/article/55995.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!