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; }