python根据文件大小打log日志

yipeiwu_com6年前Python基础

本文实例讲述了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程序设计有所帮助。

相关文章

django 中QuerySet特性功能详解

Book表的数据显示 id title   price publish_id 2 Linux   30    1 3 项塔兰   45    2 4 追风筝的人...

python3+dlib实现人脸识别和情绪分析

python3+dlib实现人脸识别和情绪分析

一、介绍 我想做的是基于人脸识别的表情(情绪)分析。看到网上也是有很多的开源库提供使用,为开发提供了很大的方便。我选择目前用的比较多的dlib库进行人脸识别与特征标定。使用python也...

好的Python培训机构应该具备哪些条件

想要追赶 Python 的热潮,应该如何学习呢?现在许多人在自学之外,都会选择去培训机构学习。选择培训机构的的标准是什么呢?什么样的python培训机构靠谱? 是否有循序...

Python中pandas dataframe删除一行或一列:drop函数详解

用法:DataFrame.drop(labels=None,axis=0, index=None, columns=None, inplace=False) 在这里默认:axis=0,指...

使用python实现滑动验证码功能

使用python实现滑动验证码功能

首先安装一个需要用到的模块 pip install social-auth-app-django 安装完后在终端输入pip list会看到 social-auth-app-djang...