#!/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")
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。