python日志按时间切分-----TimedRotatingFileHandler
2011-12-20 17:55
931 查看
原生loggging类+ TimedRotatingFileHandler类 实现按day hour second 切分
值 interval的类型
S 秒
M 分钟
H 小时
D 天
W 周
midnight 在午夜
原生loggging类+ TimedRotatingFileHandler类 实现按day hour second 切分 import logging from logging.handlers import TimedRotatingFileHandler log = logging.getLogger(loggerName) formatter = logging.Formatter('%(name)-12s %(asctime)s level-%(levelname)-8s thread-%(thread)-8d %(message)s') # 每行日志的前缀设置 fileTimeHandler = TimedRotatingFileHandler(BASIC_LOG_PATH + filename, "S", 1, 10) fileTimeHandler.suffix = "%Y%m%d.log" #设置 切分后日志文件名的时间格式 默认 filename+"." + suffix 如果需要更改需要改logging 源码 fileTimeHandler.setFormatter(formatter) logging.basicConfig(level = logging.INFO) fileTimeHandler.setFormatter(formatter) log.addHandler(fileTimeHandler) try: log.error(msg) except Exception, e: print "writeLog error" finally: log.removeHandler(fileTimeHandler)
值 interval的类型
S 秒
M 分钟
H 小时
D 天
W 周
midnight 在午夜
相关文章推荐
- [bigdata-078] python3 logging 的示例 TimedRotatingFileHandler和RotatingFileHandler 基于时间切分和基于文件大小切分
- python logging 模块之TimedRotatingFileHandler 实现每天一个日志文件
- Python多进程不要使用TimedRotatingFileHandler
- python logging现学现用 – TimedRotatingFileHandler使用方法
- python logging类库中RotatingFileHandler的使用
- Python logging RotatingFileHandler bug
- logging TimedRotatingFileHandler不支持多进程
- Python logging RotatingFileHandler bug
- 实际应用中遇到TimedRotatingFileHandler不滚动的问题
- TimedRotatingFileHandler
- Python的RotatingFileHandler的Bug
- python处理nginx日志,并统计分析---我这个写的处理时间效率不高,有好方法,请大家指正
- Python日志格式输出与时间格式
- python日志,一个改版SMTPHandler
- python TCPServer, StreamRequestHandler设置超时时间timeout
- Python实现监控程序执行时间并将其写入日志的方法
- python转换日志中的时间格式
- [Python--]tornado.web.StaticFileHandler 实现文件下载
- 使用log4j扩展包的RollingFileAppender生成带时间戳的日志文件
- python:能自动记录时间,动作发生的所在文件和行数的日志类