1 、http://sourceforge.net/projects/log4py 下载log4py,然后安装。
2、设置配置文件,请看log4py包中的log4py.conf,但是这其中没有按天,按星期,按月保存日志的设置。
3、请打开log4py.py,找到如下方法,增加下面红色部分的代码:
/*****************************************************/
def __Logger_set_instance_options(self, parser, section, instance):
""" **(private)** Set the options for a given instance from the parser section """
for i in range(len(parser.options(section))):
option = lower(parser.options(section)[i])
value = parser.get(section, option)
if (option == "format"):
instance.set_formatstring(value)
elif (option == "timeformat"):
instance.set_time_format(value)
elif (option == "ansi"):
instance.set_use_ansi_codes(upper(value))
elif (option == "loglevel"):
instance.set_loglevel(LOG_LEVELS[upper(value)])
elif(option =="rotation"):
instance.set_rotation(int(value))
elif (option == "target"):
splitted = split(value, ",")
instance.remove_all_targets()
for i in range(len(splitted)):
instance.add_target(strip(splitted[i]))
/****************************************************/
4更改配置文件log4py.conf
在其中添加: rotation =1,或者rotation =2或者rotation =3,按日,按周,按月保存。