From fba4ac09158cdf4d20b61a6084306d37b1a42eb4 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Wed, 27 Sep 2023 15:10:26 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=AF=AB=E5=85=A5=E7=A9=A9?= =?UTF-8?q?=E5=AE=9A=E6=A0=BC=E5=BC=8F=E5=8C=96=E8=99=95=E7=90=86=E5=84=AA?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/util/MyLogFormatUtil.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java index 2b51fa6b..27e04bbe 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java @@ -127,7 +127,7 @@ public class MyLogFormatUtil { List channels = Arrays.asList("59.541", "88.034", "122.061", "165.857", "391.698", "661.657", "834.838", "898.036", "1115.540", "1173.230", "1332.490", "1836.050"); List energies = Arrays.asList("0.168", "0.176", "0.174", "0.155", "0.092", "0.059", "0.051", "0.040", "0.040", "0.031", "0.028", "0.022"); - List errors = Arrays.asList("0.003", "0.004", "0.003", "0.003", "0.002", "0.001", "0.001", "0.001", "0.001", "0.001", "0.001", "0.000"); + List errors = Arrays.asList("0.003", "0.004", "0.003", "0.003", "0.002", "0.001", "0.001", "0.001", "0.001", "0.001", "0.001"); List energys = new ArrayList<>(); AttributeItemVo attributeItemVo = new AttributeItemVo(); @@ -142,7 +142,7 @@ public class MyLogFormatUtil { attributeItemVo.setAttribute("Error"); attributeItemVo.setContext(errors); energys.add(attributeItemVo); -// MyLogFormatUtil.getBlock(MyLogFormatUtil.SetSampleGEnergyChannel, "sampleId", energys); + MyLogFormatUtil.getBlock(MyLogFormatUtil.SetSampleGEnergyChannel, "sampleId", energys); Console.log(getTitleFormat("Read calibration finished",".")); @@ -294,25 +294,21 @@ public class MyLogFormatUtil { return result; } // 计算每列数据中最长的字符串长度 + StringBuilder sb = new StringBuilder(); int[] columnWidths = new int[data.get(0).size()]; for (List row : data) { for (int i = 0; i < row.size(); i++) { + // 获取长度 columnWidths[i] = Math.max(columnWidths[i], row.get(i).length()); + // 构造格式化字符串 + sb.append("%-").append(columnWidths[i] + 4).append("s"); } + // 构造格式化字符串 + result.add(String.format(sb.toString(), row.toArray())); + result.add(STRING_END); + Console.log(String.format(sb.toString(), row.toArray())); + sb = new StringBuilder(); } - - // 构造格式化字符串 - StringBuilder formatBuilder = new StringBuilder(); - for (int i = 0; i < columnWidths.length; i++) { - formatBuilder.append("%-").append(columnWidths[i] + 4).append("s"); - } - String format = formatBuilder.toString(); - // 格式化输出日志 - for (List row : data) { - result.add(String.format(format, row.toArray())); - Console.log(String.format(format, row.toArray())); - } - result.add(STRING_END); return result; }