From a9f034a06f5c954d919ca672a4ff9ec395e20368 Mon Sep 17 00:00:00 2001 From: fumingwei Date: Thu, 9 Sep 2021 09:56:25 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=E5=88=A0=E9=99=A4logging=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E4=BD=BF=E7=94=A8=E5=86=99=E6=96=87=E4=BB=B6?= =?UTF-8?q?append=E7=9A=84=E6=96=B9=E5=BC=8F=E6=93=8D=E4=BD=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images_build/client/dign_client/bin/client.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/images_build/client/dign_client/bin/client.py b/images_build/client/dign_client/bin/client.py index 53ec2af..f2c9373 100644 --- a/images_build/client/dign_client/bin/client.py +++ b/images_build/client/dign_client/bin/client.py @@ -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):