From c89650721abba039b3851755dca7e5b86cd6f813 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 13 Aug 2021 18:08:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/processors/post/MsJDBCPostProcessor.java | 2 +- .../request/processors/pre/MsJDBCPreProcessor.java | 2 +- .../dto/definition/request/sampler/MsDubboSampler.java | 2 +- .../definition/request/sampler/MsHTTPSamplerProxy.java | 2 +- .../dto/definition/request/sampler/MsJDBCSampler.java | 2 +- .../api/dto/definition/request/sampler/MsTCPSampler.java | 2 +- .../main/java/io/metersphere/api/jmeter/LocalRunner.java | 2 +- .../java/io/metersphere/api/jmeter/MsKafkaListener.java | 2 +- .../io/metersphere/api/service/ApiAutomationService.java | 6 +++--- .../api/service/ApiScenarioReportService.java | 2 +- .../io/metersphere/api/service/ApiTestCaseService.java | 4 ++-- .../java/io/metersphere/api/service/CommandService.java | 8 ++++---- .../api/service/task/ParallelScenarioExecTask.java | 2 +- .../api/service/task/SerialScenarioExecTask.java | 4 ++-- .../main/java/io/metersphere/commons/utils/LogUtil.java | 9 ++++++++- .../main/java/io/metersphere/consul/CacheNodeAspect.java | 2 +- .../main/java/io/metersphere/log/aspect/MsLogAspect.java | 4 ++-- .../java/io/metersphere/log/utils/ReflexObjectUtil.java | 4 ++-- .../java/io/metersphere/track/issue/TapdPlatform.java | 2 +- .../io/metersphere/track/service/TestCaseService.java | 2 +- .../track/service/TestPlanApiCaseService.java | 2 +- .../track/service/task/ParallelApiExecTask.java | 2 +- .../track/service/task/SerialApiExecTask.java | 4 ++-- .../track/service/utils/ParallelExecTask.java | 2 +- .../metersphere/track/service/utils/SerialExecTask.java | 2 +- .../main/java/io/metersphere/xmind/utils/FileUtil.java | 4 ++-- 26 files changed, 44 insertions(+), 37 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java index c9e826b7ec..aefa2fb72e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java @@ -198,7 +198,7 @@ public class MsJDBCPostProcessor extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java index f1387e0b93..ee7790f465 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java @@ -198,7 +198,7 @@ public class MsJDBCPreProcessor extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index 5e4af37744..a11a81f1f6 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -126,7 +126,7 @@ public class MsDubboSampler extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 649d5d755d..3133625290 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -152,7 +152,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index 8d0e92b768..b53e758b1b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -194,7 +194,7 @@ public class MsJDBCSampler extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index acad5389a6..b997823d25 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -176,7 +176,7 @@ public class MsTCPSampler extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/LocalRunner.java b/backend/src/main/java/io/metersphere/api/jmeter/LocalRunner.java index 653d068910..b2401e9233 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/LocalRunner.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/LocalRunner.java @@ -35,7 +35,7 @@ public class LocalRunner { MessageCache.runningEngine.remove(report); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java b/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java index e84b062105..ebdfe3e4f9 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java @@ -49,7 +49,7 @@ public class MsKafkaListener { } } catch (Exception e) { e.printStackTrace(); - LogUtil.error(e.getMessage()); + LogUtil.error(e); } return null; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index dd0fd36ad2..611a4b44c5 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -806,7 +806,7 @@ public class ApiAutomationService { } return bos.toByteArray(); } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } return null; } @@ -869,7 +869,7 @@ public class ApiAutomationService { } } catch (Exception e) { e.printStackTrace(); - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } @@ -1384,7 +1384,7 @@ public class ApiAutomationService { HashTree hashTree = generateHashTree(apiScenarios, request, reportIds); jMeterService.runLocal(reportIds.size() == 1 ? reportIds.get(0) : JSON.toJSONString(reportIds), hashTree, request.getReportId(), runMode); } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); MSException.throwException(e.getMessage()); } return request.getId(); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 6a5714d1ba..4a779f1231 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -413,7 +413,7 @@ public class ApiScenarioReportService { String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError())); passRateMap.put(detail.getReportId(), passRate); } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index b82e452995..598f13a23c 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -575,7 +575,7 @@ public class ApiTestCaseService { } } catch (Exception e) { e.printStackTrace(); - LogUtil.error(e.getMessage()); + LogUtil.error(e); } String requestStr = JSON.toJSONString(req); apiTestCase.setRequest(requestStr); @@ -688,7 +688,7 @@ public class ApiTestCaseService { // 调用执行方法 jMeterService.runLocal(id, jmeterHashTree, debugReportId, runMode); } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); } } return id; diff --git a/backend/src/main/java/io/metersphere/api/service/CommandService.java b/backend/src/main/java/io/metersphere/api/service/CommandService.java index d5db0b2000..c63c86bf6f 100644 --- a/backend/src/main/java/io/metersphere/api/service/CommandService.java +++ b/backend/src/main/java/io/metersphere/api/service/CommandService.java @@ -58,7 +58,7 @@ public class CommandService { FileUtils.deleteFile(path); return dtoList; } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); MSException.throwException(e.getMessage()); } return null; @@ -148,14 +148,14 @@ public class CommandService { MSException.throwException("合并条目:【" + entry.getOriginalAsName() + " 】失败"); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } }); } }); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); MSException.throwException(e.getMessage()); } } @@ -177,7 +177,7 @@ public class CommandService { } return true; } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); MSException.throwException(e.getMessage()); return false; } diff --git a/backend/src/main/java/io/metersphere/api/service/task/ParallelScenarioExecTask.java b/backend/src/main/java/io/metersphere/api/service/task/ParallelScenarioExecTask.java index 1f7d1834aa..ecb34a1618 100644 --- a/backend/src/main/java/io/metersphere/api/service/task/ParallelScenarioExecTask.java +++ b/backend/src/main/java/io/metersphere/api/service/task/ParallelScenarioExecTask.java @@ -33,7 +33,7 @@ public class ParallelScenarioExecTask implements Callable { } return null; } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException(ex.getMessage()); return null; } diff --git a/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java b/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java index ab6ccb688d..d97f9a8547 100644 --- a/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java +++ b/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java @@ -54,9 +54,9 @@ public class SerialScenarioExecTask implements Callable { } return (T) report; } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException(ex.getMessage()); return null; } } -} \ No newline at end of file +} diff --git a/backend/src/main/java/io/metersphere/commons/utils/LogUtil.java b/backend/src/main/java/io/metersphere/commons/utils/LogUtil.java index 5ce94b58cf..3b2fba94a6 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/LogUtil.java +++ b/backend/src/main/java/io/metersphere/commons/utils/LogUtil.java @@ -142,6 +142,13 @@ public class LogUtil { } } + public static void error(Throwable e) { + Logger logger = LogUtil.getLogger(); + if (logger != null && logger.isErrorEnabled()) { + logger.error(LogUtil.getMsg(e), e);// 同时打印错误堆栈信息 + } + } + public static void error(Object msg, Object o) { Logger logger = LogUtil.getLogger(); if (logger != null && logger.isErrorEnabled()) { @@ -258,4 +265,4 @@ public class LogUtil { sb.append("\n"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/backend/src/main/java/io/metersphere/consul/CacheNodeAspect.java b/backend/src/main/java/io/metersphere/consul/CacheNodeAspect.java index 536dbd02ee..56fd54d5d4 100644 --- a/backend/src/main/java/io/metersphere/consul/CacheNodeAspect.java +++ b/backend/src/main/java/io/metersphere/consul/CacheNodeAspect.java @@ -26,7 +26,7 @@ public class CacheNodeAspect { try { consulService.updateCache(); } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } diff --git a/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java b/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java index f454dc3a0a..5a15807388 100644 --- a/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java +++ b/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java @@ -107,7 +107,7 @@ public class MsLogAspect { } } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } @@ -266,7 +266,7 @@ public class MsLogAspect { operatingLogService.create(msOperLog); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } } diff --git a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java index 68f83f1084..2fec6a1d36 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -67,7 +67,7 @@ public class ReflexObjectUtil { columnList.add(column); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } } @@ -125,7 +125,7 @@ public class ReflexObjectUtil { } } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } return comparedColumns; } diff --git a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java index a2d63d3224..890ada36ad 100644 --- a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java @@ -78,7 +78,7 @@ public class TapdPlatform extends AbstractIssuePlatform { demandList.add(demand); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } return demandList; diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 257e45d539..a36dd0aef7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -776,7 +776,7 @@ public class TestCaseService { i = bis.read(buff); } } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException("下载思维导图模版失败"); } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java index 7cd65e6cda..fc4c067bee 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -317,7 +317,7 @@ public class TestPlanApiCaseService { } } catch (Exception e) { e.printStackTrace(); - LogUtil.error(e.getMessage()); + LogUtil.error(e); } return null; } diff --git a/backend/src/main/java/io/metersphere/track/service/task/ParallelApiExecTask.java b/backend/src/main/java/io/metersphere/track/service/task/ParallelApiExecTask.java index 111be783b6..ec376a6af1 100644 --- a/backend/src/main/java/io/metersphere/track/service/task/ParallelApiExecTask.java +++ b/backend/src/main/java/io/metersphere/track/service/task/ParallelApiExecTask.java @@ -38,7 +38,7 @@ public class ParallelApiExecTask implements Callable { } return null; } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException(ex.getMessage()); return null; } diff --git a/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java b/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java index 7728003b75..0e5e51a2cc 100644 --- a/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java +++ b/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java @@ -56,9 +56,9 @@ public class SerialApiExecTask implements Callable { } return (T) report; } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException(ex.getMessage()); return null; } } -} \ No newline at end of file +} diff --git a/backend/src/main/java/io/metersphere/track/service/utils/ParallelExecTask.java b/backend/src/main/java/io/metersphere/track/service/utils/ParallelExecTask.java index 0901c84a4e..2828d97a4f 100644 --- a/backend/src/main/java/io/metersphere/track/service/utils/ParallelExecTask.java +++ b/backend/src/main/java/io/metersphere/track/service/utils/ParallelExecTask.java @@ -35,7 +35,7 @@ public class ParallelExecTask implements Callable { return (T) reportId; } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException(ex.getMessage()); return null; } diff --git a/backend/src/main/java/io/metersphere/track/service/utils/SerialExecTask.java b/backend/src/main/java/io/metersphere/track/service/utils/SerialExecTask.java index bf61690e6b..94949dd825 100644 --- a/backend/src/main/java/io/metersphere/track/service/utils/SerialExecTask.java +++ b/backend/src/main/java/io/metersphere/track/service/utils/SerialExecTask.java @@ -54,7 +54,7 @@ public class SerialExecTask implements Callable { return (T) report; } catch (Exception ex) { - LogUtil.error(ex.getMessage()); + LogUtil.error(ex); MSException.throwException(ex.getMessage()); return null; } diff --git a/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java b/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java index ecb7878c75..80f9971998 100644 --- a/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java +++ b/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java @@ -24,7 +24,7 @@ public class FileUtil { os.write(buffer, 0, bytesRead); } } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } @@ -41,7 +41,7 @@ public class FileUtil { inputStreamToFile(ins, toFile); return toFile; } catch (Exception e) { - LogUtil.error(e.getMessage()); + LogUtil.error(e); } } return null;