1. 程式人生 > >python設置日誌信息

python設置日誌信息

success argv ssa level evel 日誌信息 %s sys.argv comm

#!/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--)

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

python設置日誌信息