首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python 之循环日记

2013-01-01 
Python 之循环日志Python 之循环日志参考:http://docs.python.org/2/library/logging.htmlRotatingFileHan

Python 之循环日志

Python 之循环日志

参考:

http://docs.python.org/2/library/logging.html

RotatingFileHandler 用于处理循环日志, 可以指定日志文件级别,日志文件最大容量(字节),日志文件

#!/usr/bin/python# filename: printlog.py# author: # date: 2012-12-19# version: 0.1import loggingfrom logging.handlers import RotatingFileHandler## log settingsLOG_PATH_FILE = "./print.log"LOG_MODE = 'a'LOG_MAX_SIZE = 2*1024*1024 # 2MLOG_MAX_FILES = 4 # 4 Files: print.log.1, print.log.2, print.log.3, print.log.4LOG_LEVEL = logging.DEBUGLOG_FORMAT = "%(asctime)s %(levelname)-10s[%(filename)s:%(lineno)d(%(funcName)s)] %(message)s"handler = RotatingFileHandler(LOG_PATH_FILE, LOG_MODE, LOG_MAX_SIZE, LOG_MAX_FILES)formatter = logging.Formatter(LOG_FORMAT)handler.setFormatter(formatter)Logger = logging.getLogger()Logger.setLevel(LOG_LEVEL)Logger.addHandler(handler)i=0while i < 10000:  i = i+1  Logger.log(logging.DEBUG, "Logs a message with integer level lvl on this logger.")  Logger.info("Logs a message with level INFO on this logger.")  Logger.warning("Logs a message with level WARNING on this logger.")  Logger.error("Logs a message with level ERROR on this logger.")  Logger.critical("Logs a message with level CRITICAL on this logger.")# Logger.exception("This method should only be called from an exception handler.")


热点排行