refactor: 优化日志打印

This commit is contained in:
chenjianxing 2021-08-13 18:08:55 +08:00 committed by jianxing
parent e4aa582d47
commit c89650721a
26 changed files with 44 additions and 37 deletions

View File

@ -198,7 +198,7 @@ public class MsJDBCPostProcessor extends MsTestElement {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }

View File

@ -198,7 +198,7 @@ public class MsJDBCPreProcessor extends MsTestElement {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }

View File

@ -126,7 +126,7 @@ public class MsDubboSampler extends MsTestElement {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }

View File

@ -152,7 +152,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }

View File

@ -194,7 +194,7 @@ public class MsJDBCSampler extends MsTestElement {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }

View File

@ -176,7 +176,7 @@ public class MsTCPSampler extends MsTestElement {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }

View File

@ -35,7 +35,7 @@ public class LocalRunner {
MessageCache.runningEngine.remove(report); MessageCache.runningEngine.remove(report);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
} }

View File

@ -49,7 +49,7 @@ public class MsKafkaListener {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
return null; return null;
} }

View File

@ -806,7 +806,7 @@ public class ApiAutomationService {
} }
return bos.toByteArray(); return bos.toByteArray();
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
return null; return null;
} }
@ -869,7 +869,7 @@ public class ApiAutomationService {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
@ -1384,7 +1384,7 @@ public class ApiAutomationService {
HashTree hashTree = generateHashTree(apiScenarios, request, reportIds); HashTree hashTree = generateHashTree(apiScenarios, request, reportIds);
jMeterService.runLocal(reportIds.size() == 1 ? reportIds.get(0) : JSON.toJSONString(reportIds), hashTree, request.getReportId(), runMode); jMeterService.runLocal(reportIds.size() == 1 ? reportIds.get(0) : JSON.toJSONString(reportIds), hashTree, request.getReportId(), runMode);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
MSException.throwException(e.getMessage()); MSException.throwException(e.getMessage());
} }
return request.getId(); return request.getId();

View File

@ -413,7 +413,7 @@ public class ApiScenarioReportService {
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError())); String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
passRateMap.put(detail.getReportId(), passRate); passRateMap.put(detail.getReportId(), passRate);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }

View File

@ -575,7 +575,7 @@ public class ApiTestCaseService {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
String requestStr = JSON.toJSONString(req); String requestStr = JSON.toJSONString(req);
apiTestCase.setRequest(requestStr); apiTestCase.setRequest(requestStr);
@ -688,7 +688,7 @@ public class ApiTestCaseService {
// 调用执行方法 // 调用执行方法
jMeterService.runLocal(id, jmeterHashTree, debugReportId, runMode); jMeterService.runLocal(id, jmeterHashTree, debugReportId, runMode);
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
} }
} }
return id; return id;

View File

@ -58,7 +58,7 @@ public class CommandService {
FileUtils.deleteFile(path); FileUtils.deleteFile(path);
return dtoList; return dtoList;
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
MSException.throwException(e.getMessage()); MSException.throwException(e.getMessage());
} }
return null; return null;
@ -148,14 +148,14 @@ public class CommandService {
MSException.throwException("合并条目:【" + entry.getOriginalAsName() + " 】失败"); MSException.throwException("合并条目:【" + entry.getOriginalAsName() + " 】失败");
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
}); });
} }
}); });
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
MSException.throwException(e.getMessage()); MSException.throwException(e.getMessage());
} }
} }
@ -177,7 +177,7 @@ public class CommandService {
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
MSException.throwException(e.getMessage()); MSException.throwException(e.getMessage());
return false; return false;
} }

View File

@ -33,7 +33,7 @@ public class ParallelScenarioExecTask<T> implements Callable<T> {
} }
return null; return null;
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException(ex.getMessage()); MSException.throwException(ex.getMessage());
return null; return null;
} }

View File

@ -54,9 +54,9 @@ public class SerialScenarioExecTask<T> implements Callable<T> {
} }
return (T) report; return (T) report;
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException(ex.getMessage()); MSException.throwException(ex.getMessage());
return null; return null;
} }
} }
} }

View File

@ -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) { public static void error(Object msg, Object o) {
Logger logger = LogUtil.getLogger(); Logger logger = LogUtil.getLogger();
if (logger != null && logger.isErrorEnabled()) { if (logger != null && logger.isErrorEnabled()) {
@ -258,4 +265,4 @@ public class LogUtil {
sb.append("\n"); sb.append("\n");
return sb.toString(); return sb.toString();
} }
} }

View File

@ -26,7 +26,7 @@ public class CacheNodeAspect {
try { try {
consulService.updateCache(); consulService.updateCache();
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }

View File

@ -107,7 +107,7 @@ public class MsLogAspect {
} }
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
@ -266,7 +266,7 @@ public class MsLogAspect {
operatingLogService.create(msOperLog); operatingLogService.create(msOperLog);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
} }

View File

@ -67,7 +67,7 @@ public class ReflexObjectUtil {
columnList.add(column); columnList.add(column);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
} }
@ -125,7 +125,7 @@ public class ReflexObjectUtil {
} }
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
return comparedColumns; return comparedColumns;
} }

View File

@ -78,7 +78,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
demandList.add(demand); demandList.add(demand);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
return demandList; return demandList;

View File

@ -776,7 +776,7 @@ public class TestCaseService {
i = bis.read(buff); i = bis.read(buff);
} }
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException("下载思维导图模版失败"); MSException.throwException("下载思维导图模版失败");
} }
} }

View File

@ -317,7 +317,7 @@ public class TestPlanApiCaseService {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
return null; return null;
} }

View File

@ -38,7 +38,7 @@ public class ParallelApiExecTask<T> implements Callable<T> {
} }
return null; return null;
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException(ex.getMessage()); MSException.throwException(ex.getMessage());
return null; return null;
} }

View File

@ -56,9 +56,9 @@ public class SerialApiExecTask<T> implements Callable<T> {
} }
return (T) report; return (T) report;
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException(ex.getMessage()); MSException.throwException(ex.getMessage());
return null; return null;
} }
} }
} }

View File

@ -35,7 +35,7 @@ public class ParallelExecTask<T> implements Callable<T> {
return (T) reportId; return (T) reportId;
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException(ex.getMessage()); MSException.throwException(ex.getMessage());
return null; return null;
} }

View File

@ -54,7 +54,7 @@ public class SerialExecTask<T> implements Callable<T> {
return (T) report; return (T) report;
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex);
MSException.throwException(ex.getMessage()); MSException.throwException(ex.getMessage());
return null; return null;
} }

View File

@ -24,7 +24,7 @@ public class FileUtil {
os.write(buffer, 0, bytesRead); os.write(buffer, 0, bytesRead);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
@ -41,7 +41,7 @@ public class FileUtil {
inputStreamToFile(ins, toFile); inputStreamToFile(ins, toFile);
return toFile; return toFile;
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage()); LogUtil.error(e);
} }
} }
return null; return null;