bugfix:删除logging使用,使用写文件append的方式操作日志文件

This commit is contained in:
fumingwei
2021-09-09 09:56:25 +08:00
parent 7610165837
commit a9f034a06f

View File

@@ -301,8 +301,8 @@ class DignTextTestResult(unittest.result.TestResult):
self.stream.writeln("%s" % err)
self.dignStream.writeln("%s" % err)
def get_logger(logPath,enableConsole=True):
logger = logging.getLogger()
def get_logger(name,logPath,enableConsole=True):
logger = logging.getLogger(name)
fileHandler = logging.FileHandler(logPath)
fmt = '%(asctime)s, %(levelname)s, %(message)s'
formatter = logging.Formatter(fmt=fmt, datefmt='%a %b %d %H:%M:%S %Y')
@@ -780,11 +780,13 @@ class SSLFileDownloadBuild:
def _write_in_logfile(self, sizeStr, connInfoDict):
connInfoLogPath = "/opt/dign_client/log/download_conn_info.log" + '.' + time.strftime("%Y-%m-%d", time.localtime())
connInfoLogger = get_logger(connInfoLogPath,enableConsole=False)
#connInfoLogger = get_logger("download",connInfoLogPath,enableConsole=False)
connInfoStr = json.dumps(connInfoDict)
connInfoLogger.debug("Fize Size:" + sizeStr + ";connection info:" + connInfoStr)
#connInfoLogger.debug("Fize Size:" + sizeStr + ";connection info:" + connInfoStr)
with open(connInfoLogPath,"a+") as f:
f.write(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) + "Fize Size:" + sizeStr + ";connection info:" + connInfoStr + '\n')
f.close()
def conn_traffic(self,test_suite_name,url,conn_taffic_re,sizeStr, size):
self._set_conn_opt(test_suite_name, url)
self.conn.perform()
@@ -1204,12 +1206,19 @@ class TsgDiagnose:
def _dign_running(self):
print(format(("Test start time: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())),'#^120s'))
runningLogPath = "/opt/dign_client/log/tsg-diagnose.log" + '.' + time.strftime("%Y-%m-%d", time.localtime())
runningLogger = get_logger(runningLogPath, False)
runningLogger.debug("Diagnose Start,the It will take up to %d seconds" %(self.dign_duration))
#runningLogger = get_logger("running",runningLogPath, False)
#runningLogger.debug("Diagnose Start,the It will take up to %d seconds" %(self.dign_duration))
with open(runningLogPath,"a+") as f:
f.write(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) + "Diagnose Start,the It will take up to " + str(self.dign_duration) + " senconds")
f.write('\n')
f.close()
result_stream = io.StringIO()
runner = unittest.TextTestRunner(stream=result_stream,verbosity=2,resultclass=DignTextTestResult)
runner.run(self.suite)
runningLogger.debug("Diagnose end, Testing results:" + "\n" + result_stream.getvalue())
with open(runningLogPath,"a+") as f:
f.write(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) + "Diagnose end, Testing results:" + "\n" + result_stream.getvalue())
f.close()
#runningLogger.debug("Diagnose end, Testing results:" + "\n" + result_stream.getvalue())
print(format(("Test end time: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())),'=^120s'))
def dign_exec(self):