本文实例讲述了python根据文件大小打log日志的方法,分享给大家供大家参考。具体方法如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20import 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日志内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复