使用python生成日志

zhangzm 9年前發布 | 10K 次閱讀 Python開發 Python

-- coding: gb2312 --


import time 
from common.mkdir import mkdir
class writeLog(object):
    '''
        寫日志文件
    '''
    def writeLog(self,logPath,testCaseName,log):
        self.mkdir = mkdir()
        self.actPath = self.mkdir.mkdir(logPath)
        currentTime = time.strftime('%Y-%m-%d %H-%M-%S',time.localtime(time.time()))
        fname = self.actPath + "\"+currentTime+".log"
        fobj = open(fname,'w')
        date = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        fobj.writelines(u'用例名稱:' + testCaseName +'\n'+
                        u'日期:'+ date +'\n'+
                        u'日志內容:'+log
                        )
        fobj.close()

 本文由用戶 zhangzm 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!