bugfix:删除logging使用,使用写文件append的方式操作日志文件
This commit is contained in:
@@ -301,8 +301,8 @@ class DignTextTestResult(unittest.result.TestResult):
|
|||||||
self.stream.writeln("%s" % err)
|
self.stream.writeln("%s" % err)
|
||||||
self.dignStream.writeln("%s" % err)
|
self.dignStream.writeln("%s" % err)
|
||||||
|
|
||||||
def get_logger(logPath,enableConsole=True):
|
def get_logger(name,logPath,enableConsole=True):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger(name)
|
||||||
fileHandler = logging.FileHandler(logPath)
|
fileHandler = logging.FileHandler(logPath)
|
||||||
fmt = '%(asctime)s, %(levelname)s, %(message)s'
|
fmt = '%(asctime)s, %(levelname)s, %(message)s'
|
||||||
formatter = logging.Formatter(fmt=fmt, datefmt='%a %b %d %H:%M:%S %Y')
|
formatter = logging.Formatter(fmt=fmt, datefmt='%a %b %d %H:%M:%S %Y')
|
||||||
@@ -780,10 +780,12 @@ class SSLFileDownloadBuild:
|
|||||||
|
|
||||||
def _write_in_logfile(self, sizeStr, connInfoDict):
|
def _write_in_logfile(self, sizeStr, connInfoDict):
|
||||||
connInfoLogPath = "/opt/dign_client/log/download_conn_info.log" + '.' + time.strftime("%Y-%m-%d", time.localtime())
|
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)
|
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):
|
def conn_traffic(self,test_suite_name,url,conn_taffic_re,sizeStr, size):
|
||||||
self._set_conn_opt(test_suite_name, url)
|
self._set_conn_opt(test_suite_name, url)
|
||||||
@@ -1204,12 +1206,19 @@ class TsgDiagnose:
|
|||||||
def _dign_running(self):
|
def _dign_running(self):
|
||||||
print(format(("Test start time: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())),'#^120s'))
|
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())
|
runningLogPath = "/opt/dign_client/log/tsg-diagnose.log" + '.' + time.strftime("%Y-%m-%d", time.localtime())
|
||||||
runningLogger = get_logger(runningLogPath, False)
|
#runningLogger = get_logger("running",runningLogPath, False)
|
||||||
runningLogger.debug("Diagnose Start,the It will take up to %d seconds" %(self.dign_duration))
|
#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()
|
result_stream = io.StringIO()
|
||||||
runner = unittest.TextTestRunner(stream=result_stream,verbosity=2,resultclass=DignTextTestResult)
|
runner = unittest.TextTestRunner(stream=result_stream,verbosity=2,resultclass=DignTextTestResult)
|
||||||
runner.run(self.suite)
|
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'))
|
print(format(("Test end time: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())),'=^120s'))
|
||||||
|
|
||||||
def dign_exec(self):
|
def dign_exec(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user