#!/usr/bin/env python
import sys, time, logging, commands

'''Set log output parameters'''

def setting_logger():
timedate = time.strftime("%Y-%m-%d%H:%M:%S", time.localtime())
logfilename = "%s%s.log" % (sys.argv[0].split(".")[0], time_date)
logger_formatter_str = '%(asctime)s %(filename)s[line:%(lineno)d] %(name)s %(levelname)s %(message)s'
logging.basicConfig(filename=log_filename, level=logging.INFO, format=logger_formatter_str,
stream=sys.stdout)
return logging.getLogger(--name--)

主要是logging.basicConfig的设置:
1 filename:指的是日志文件以及目录;
2 format,日志的格式;
3 level, 日志的级别;
4 filemode:日志打开的模式,a是追加,w代表覆盖;

使用方法:
setting_logger().info("delete_successfully")