python根据文件大小打log日志
作者:shichen2014 时间:2022-04-28 06:29:35
本文实例讲述了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,日志
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python没有gpu,如何改用cpu跑代码
2022-09-26 00:24:49
![](https://img.aspxhome.com/file/2023/7/101137_0s.png)
使用python实现baidu hi自动登录的代码
2021-11-23 14:54:32
Python 连连看连接算法
2023-10-28 09:12:35
Python实现求解最大公约数的五种方法总结
2023-07-02 20:34:46
python中单双下划线的区别对比分析
2023-12-18 23:58:45
![](https://img.aspxhome.com/file/2023/7/105857_0s.png)
matlab和Excel的数据交互操作(非xlsread和xlswrite)
2022-06-16 01:00:42
![](https://img.aspxhome.com/file/2023/4/76894_0s.png)
python中yield的用法详解
2023-06-10 00:43:56
基于python爬虫数据处理(详解)
2023-06-07 11:38:39
![](https://img.aspxhome.com/file/2023/0/120350_0s.jpg)
python实现人像动漫化的示例代码
2021-08-16 06:36:17
![](https://img.aspxhome.com/file/2023/7/130977_0s.jpg)
Python基于Tkinter开发一个爬取B站直播弹幕的工具
2023-06-21 21:53:12
![](https://img.aspxhome.com/file/2023/7/68867_0s.png)
Jupyter notebook运行后打不开网页的问题解决
2021-07-10 01:35:30
![](https://img.aspxhome.com/file/2023/8/118348_0s.jpg)
用JavaScript实现PHP的urlencode与urldecode函数
2023-11-23 08:18:14
一小时学会TensorFlow2之基本操作1实例代码
2023-03-01 23:58:10
![](https://img.aspxhome.com/file/2023/5/94175_0s.jpg)
python读取浮点数和读取文本文件示例
2022-10-31 16:03:38
MySQL的数据库常用命令 超级实用版分享
2012-01-05 18:58:00
实例:arguments.callee的应用
2009-04-20 12:38:00
深入理解Python中的 __new__ 和 __init__及区别介绍
2022-11-15 12:23:36
pycharm使用技巧之自动调整代码格式总结
2021-08-28 08:13:18
![](https://img.aspxhome.com/file/2023/7/75117_0s.png)
JS重现80后儿时经典拼板(模板)游戏
2011-09-11 18:36:46
Python迭代器与生成器用法实例分析
2023-08-23 05:52:38