创建mylog.py文件,以下为解析内容:
1、导入需要的文件
os:用来获取当前工程的路径
logging:用来设置日志的属性
time:用来获取当前系统的日期
2、在另外一个文件导入该文件,然后执行writeLog即可,第一个参数为log的名字,第二个参数为log的内容
比如:
from Utility.myLog import *
writeLog("test", "message")
'''
Created on 2012-11-17@author: Administrator
'''
# encoding:utf-8
import os,logging,time
p= os.environ.get('PROJECT_LOC')
def writeLog(log_name,message):
format = time.strftime('%y-%m-%d',time.localtime(time.time()))
LOG_FILENAME = p + "./TestResult/Log/"+ log_name + "_" +format + ".log"
logging.basicConfig(filename=LOG_FILENAME,level=logging.info)
logging.info(message)
转载来源:http://blog.youkuaiyun.com/shandong_chu/article/details/8194898