refactor: 完善日志打印

This commit is contained in:
chenjianxing 2020-11-25 10:36:30 +08:00
parent 83daf96f01
commit 754f067cdd
20 changed files with 46 additions and 46 deletions

View File

@ -161,13 +161,13 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
testPlanTestCaseService.updateTestCaseStates(ids, TestPlanTestCaseStatus.Failure.name()); testPlanTestCaseService.updateTestCaseStates(ids, TestPlanTestCaseStatus.Failure.name());
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
try { try {
sendTask(report, testResult); sendTask(report, testResult);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }

View File

@ -50,7 +50,7 @@ public class JmeterDocumentParser {
} }
return documentToBytes(document); return documentToBytes(document);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
return source; return source;
} }
} }

View File

@ -131,7 +131,7 @@ public class APITestService {
file.createNewFile(); file.createNewFile();
FileUtil.copyStream(in, out); FileUtil.copyStream(in, out);
} catch (IOException e) { } catch (IOException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("upload_fail")); MSException.throwException(Translator.get("upload_fail"));
} }
} }
@ -174,7 +174,7 @@ public class APITestService {
try { try {
FileUtil.copyDir(sourceFile, new File(targetDir)); FileUtil.copyDir(sourceFile, new File(targetDir));
} catch (IOException e) { } catch (IOException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("upload_fail")); MSException.throwException(Translator.get("upload_fail"));
} }
} }
@ -437,7 +437,7 @@ public class APITestService {
bytes = JmeterDocumentParser.parse(bytes); bytes = JmeterDocumentParser.parse(bytes);
is = new ByteArrayInputStream(bytes); is = new ByteArrayInputStream(bytes);
} catch (IOException e) { } catch (IOException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
jMeterService.run(request.getId(), reportId, is); jMeterService.run(request.getId(), reportId, is);

View File

@ -88,7 +88,7 @@ public class CompressUtils {
gzip.finish(); gzip.finish();
return obj.toByteArray(); return obj.toByteArray();
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
return data; return data;
} }
} }
@ -116,7 +116,7 @@ public class CompressUtils {
baos.flush(); baos.flush();
return baos.toByteArray(); return baos.toByteArray();
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
return data; return data;
} }
} }

View File

@ -18,7 +18,7 @@ public class ScriptEngineUtils {
String script = IOUtils.toString(ScriptEngineUtils.class.getResource("/javascript/func.js"), StandardCharsets.UTF_8); String script = IOUtils.toString(ScriptEngineUtils.class.getResource("/javascript/func.js"), StandardCharsets.UTF_8);
engine.eval(script); engine.eval(script);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -26,7 +26,7 @@ public class ScriptEngineUtils {
try { try {
return engine.eval("calculate('" + input + "')").toString(); return engine.eval("calculate('" + input + "')").toString();
} catch (ScriptException e) { } catch (ScriptException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
return input; return input;
} }
} }

View File

@ -66,7 +66,7 @@ public class DingTaskService {
try { try {
response = client.execute(request); response = client.execute(request);
} catch (ApiException e) { } catch (ApiException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
System.out.println(response.getErrcode()); System.out.println(response.getErrcode());
} }

View File

@ -65,7 +65,7 @@ public class MailService {
} }
sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, performanceTemplate, loadTestReport.getTriggerMode()); sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, performanceTemplate, loadTestReport.getTriggerMode());
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -86,7 +86,7 @@ public class MailService {
} }
sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, apiTemplate, apiTestReport.getTriggerMode()); sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, apiTemplate, apiTestReport.getTriggerMode());
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -118,7 +118,7 @@ public class MailService {
try { try {
javaMailSender.send(mimeMessage); javaMailSender.send(mimeMessage);
} catch (MailException e) { } catch (MailException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
//测试评审 //测试评审
@ -129,7 +129,7 @@ public class MailService {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewEnd.html"), StandardCharsets.UTF_8); String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewEnd.html"), StandardCharsets.UTF_8);
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -139,7 +139,7 @@ public class MailService {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewDelete.html"), StandardCharsets.UTF_8); String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewDelete.html"), StandardCharsets.UTF_8);
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -156,7 +156,7 @@ public class MailService {
String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewComments.html"), StandardCharsets.UTF_8); String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewComments.html"), StandardCharsets.UTF_8);
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, commentTemplate); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, commentTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -166,7 +166,7 @@ public class MailService {
String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewInitiate.html"), StandardCharsets.UTF_8); String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewInitiate.html"), StandardCharsets.UTF_8);
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, reviewerTemplate); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, reviewerTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -205,7 +205,7 @@ public class MailService {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanStart.html"), StandardCharsets.UTF_8); String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanStart.html"), StandardCharsets.UTF_8);
sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -217,7 +217,7 @@ public class MailService {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanEnd.html"), StandardCharsets.UTF_8); String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanEnd.html"), StandardCharsets.UTF_8);
sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -229,7 +229,7 @@ public class MailService {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanDelete.html"), StandardCharsets.UTF_8); String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanDelete.html"), StandardCharsets.UTF_8);
sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -266,7 +266,7 @@ public class MailService {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/IssuesCreate.html"), StandardCharsets.UTF_8); String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/IssuesCreate.html"), StandardCharsets.UTF_8);
sendIssuesNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); sendIssuesNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }

View File

@ -59,7 +59,7 @@ public class WxChatTaskService {
SendResult result = WxChatbotClient.send(Webhook, message); SendResult result = WxChatbotClient.send(Webhook, message);
System.out.println(result); System.out.println(result);
} catch (IOException e) { } catch (IOException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }

View File

@ -139,10 +139,10 @@ public class EngineFactory {
String content = engineSourceParser.parse(engineContext, source); String content = engineSourceParser.parse(engineContext, source);
engineContext.setContent(content); engineContext.setContent(content);
} catch (MSException e) { } catch (MSException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(e); MSException.throwException(e);
} }

View File

@ -64,10 +64,10 @@ public class DockerTestEngine extends AbstractEngine {
try { try {
context = EngineFactory.createContext(loadTest, resource.getId(), ratio, this.getStartTime(), this.getReportId(), resourceIndex); context = EngineFactory.createContext(loadTest, resource.getId(), ratio, this.getStartTime(), this.getReportId(), resourceIndex);
} catch (MSException e) { } catch (MSException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(e); MSException.throwException(e);
} }

View File

@ -65,7 +65,7 @@ public class PerformanceNoticeTask {
//查询定时任务是否关闭 //查询定时任务是否关闭
Thread.sleep(1000 * 30);// 每分钟检查 loadtest 的状态 Thread.sleep(1000 * 30);// 每分钟检查 loadtest 的状态
} catch (InterruptedException e) { } catch (InterruptedException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
}); });

View File

@ -258,7 +258,7 @@ public class PerformanceTestService {
soc.close(); soc.close();
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("load_test_kafka_invalid")); MSException.throwException(Translator.get("load_test_kafka_invalid"));
} }
} }
@ -304,7 +304,7 @@ public class PerformanceTestService {
} catch (MSException e) { } catch (MSException e) {
// 启动失败之后清理任务 // 启动失败之后清理任务
engine.stop(); engine.stop();
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
loadTest.setStatus(PerformanceTestStatus.Error.name()); loadTest.setStatus(PerformanceTestStatus.Error.name());
loadTest.setDescription(e.getMessage()); loadTest.setDescription(e.getMessage());
loadTestMapper.updateByPrimaryKeySelective(loadTest); loadTestMapper.updateByPrimaryKeySelective(loadTest);

View File

@ -119,7 +119,7 @@ public class JarConfigService {
file.createNewFile(); file.createNewFile();
FileUtil.copyStream(in, out); FileUtil.copyStream(in, out);
} catch (IOException e) { } catch (IOException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("upload_fail")); MSException.throwException(Translator.get("upload_fail"));
} }
return filePath; return filePath;

View File

@ -107,7 +107,7 @@ public class SystemParameterService {
try { try {
javaMailSender.testConnection(); javaMailSender.testConnection();
} catch (MessagingException e) { } catch (MessagingException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("connection_failed")); MSException.throwException(Translator.get("connection_failed"));
} }
} }

View File

@ -135,7 +135,7 @@ public class TestResourcePoolService {
MSException.throwException("Resource Pool is invalid."); MSException.throwException("Resource Pool is invalid.");
} }
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -161,7 +161,7 @@ public class TestResourcePoolService {
testResourcePoolDTO.setResources(testResources); testResourcePoolDTO.setResources(testResources);
testResourcePoolDTOS.add(testResourcePoolDTO); testResourcePoolDTOS.add(testResourcePoolDTO);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
}); });
return testResourcePoolDTOS; return testResourcePoolDTOS;
@ -210,7 +210,7 @@ public class TestResourcePoolService {
ResponseEntity<String> entity = restTemplateWithTimeOut.getForEntity(String.format(nodeControllerUrl, node.getIp(), node.getPort()), String.class); ResponseEntity<String> entity = restTemplateWithTimeOut.getForEntity(String.format(nodeControllerUrl, node.getIp(), node.getPort()), String.class);
return HttpStatus.OK.equals(entity.getStatusCode()); return HttpStatus.OK.equals(entity.getStatusCode());
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
return false; return false;
} }
} }

View File

@ -116,7 +116,7 @@ public class IssuesService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }

View File

@ -84,7 +84,7 @@ public class TestCaseCommentService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }

View File

@ -127,7 +127,7 @@ public class TestCaseReviewService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -205,7 +205,7 @@ public class TestCaseReviewService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -316,7 +316,7 @@ public class TestCaseReviewService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -466,7 +466,7 @@ public class TestCaseReviewService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
} }

View File

@ -137,7 +137,7 @@ public class TestPlanService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
@ -188,7 +188,7 @@ public class TestPlanService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
return i; return i;
@ -272,7 +272,7 @@ public class TestPlanService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
return num; return num;
} }
@ -513,7 +513,7 @@ public class TestPlanService {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }

View File

@ -106,7 +106,7 @@ public class ReportWebSocket {
} }
Thread.sleep(20 * 1000L); Thread.sleep(20 * 1000L);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e.getMessage(), e);
} }
} }
} }