From 39a1ced25e6b5d3f600472d692702ec7ca01829b Mon Sep 17 00:00:00 2001 From: Axel Howind Date: Wed, 21 Feb 2024 21:28:04 +0000 Subject: [PATCH] fix Logging issues: - don't use foreign class in Logger initialization - update log statements to use MessageFormat syntax git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1915930 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/openxml4j/util/ZipSecureFile.java | 4 ++-- .../poi/xddf/usermodel/chart/XDDFChartData.java | 4 ++-- .../apache/poi/openxml4j/opc/TestRelationships.java | 2 +- .../apache/poi/hslf/record/EscherPlaceholder.java | 2 +- .../org/apache/poi/hslf/record/SSSlideInfoAtom.java | 10 +++++----- .../org/apache/poi/hwpf/model/OfficeArtContent.java | 2 +- .../java/org/apache/poi/hwpf/model/StyleSheet.java | 12 ++++++------ .../poi/hwpf/converter/TestWordToTextConverter.java | 6 +++--- .../java/org/apache/poi/ss/format/CellFormat.java | 2 +- .../org/apache/poi/ss/format/CellFormatPart.java | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java index fbc5781fdd..f87c0bdd7a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java @@ -119,7 +119,7 @@ public class ZipSecureFile extends ZipFile { if (maxEntrySize < 0) { throw new IllegalArgumentException("Max entry size must be greater than or equal to zero"); } else if (maxEntrySize > DEFAULT_MAX_ENTRY_SIZE) { - LOG.atWarn().log("setting max entry size greater than 4Gb can be risky; set to " + maxEntrySize + " bytes"); + LOG.warn("setting max entry size greater than 4Gb can be risky; set to {} bytes", maxEntrySize); } MAX_ENTRY_SIZE = maxEntrySize; } @@ -183,7 +183,7 @@ public class ZipSecureFile extends ZipFile { if (maxTextSize < 0) { throw new IllegalArgumentException("Max text size must be greater than or equal to zero"); }else if (maxTextSize > DEFAULT_MAX_TEXT_SIZE) { - LOG.atWarn().log("setting max text size greater than " + DEFAULT_MAX_TEXT_SIZE + " can be risky; set to " + maxTextSize + " chars"); + LOG.warn("setting max text size greater than {} can be risky; set to {} chars", DEFAULT_MAX_TEXT_SIZE, maxTextSize); } MAX_TEXT_SIZE = maxTextSize; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java index c8e92fea64..ae2ae1c12c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java @@ -170,8 +170,8 @@ public abstract class XDDFChartData { if (categoryData != null && values != null) { int numOfPoints = category.getPointCount(); if (numOfPoints != values.getPointCount()) { - LOGGER.warn("Category and values must have the same point count, but had " + - numOfPoints + " categories and " + values.getPointCount() + " values."); + LOGGER.warn("Category and values must have the same point count, but had {}" + + " categories and {} values.", numOfPoints, values.getPointCount()); } } this.categoryData = category; diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java index ce63f811a8..6af8b2c1f3 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java @@ -44,7 +44,7 @@ class TestRelationships { private static final String SHEET_WITH_COMMENTS = "/xl/worksheets/sheet1.xml"; - private static final Logger LOG = LogManager.getLogger(TestPackageCoreProperties.class); + private static final Logger LOG = LogManager.getLogger(TestRelationships.class); /** * Test relationships are correctly loaded. This at the moment fails (as of r499) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherPlaceholder.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherPlaceholder.java index f474f2171c..92088abca5 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherPlaceholder.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherPlaceholder.java @@ -64,7 +64,7 @@ public class EscherPlaceholder extends EscherRecord { unused = LittleEndian.getShort(data, offset+14); if (bytesRemaining + 8 != 16) { - LOG.warn("Invalid header-data received, should have 8 bytes left, but had: " + bytesRemaining); + LOG.warn("Invalid header-data received, should have 8 bytes left, but had: {}", bytesRemaining); } return bytesRemaining + 8; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SSSlideInfoAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SSSlideInfoAtom.java index 89d26a6f30..cf082b6749 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SSSlideInfoAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SSSlideInfoAtom.java @@ -203,21 +203,21 @@ public class SSSlideInfoAtom extends RecordAtom { ofs += _header.length; if (LittleEndian.getShort(_header, 0) != 0) { - LOG.atDebug().log("Invalid data for SSSlideInfoAtom at offset 0: " + LittleEndian.getShort(_header, 0)); + LOG.debug("Invalid data for SSSlideInfoAtom at offset 0: {}", LittleEndian.getShort(_header, 0)); } if (LittleEndian.getShort(_header, 2) != RecordTypes.SSSlideInfoAtom.typeID) { - LOG.atDebug().log("Invalid data for SSSlideInfoAtom at offset 2: "+ LittleEndian.getShort(_header, 2)); + LOG.debug("Invalid data for SSSlideInfoAtom at offset 2: {}", LittleEndian.getShort(_header, 2)); } if (LittleEndian.getShort(_header, 4) != 0x10) { - LOG.atDebug().log("Invalid data for SSSlideInfoAtom at offset 4: "+ LittleEndian.getShort(_header, 4)); + LOG.debug("Invalid data for SSSlideInfoAtom at offset 4: {}", LittleEndian.getShort(_header, 4)); } if (LittleEndian.getShort(_header, 6) == 0) { - LOG.atDebug().log("Invalid data for SSSlideInfoAtom at offset 6: "+ LittleEndian.getShort(_header, 6)); + LOG.debug("Invalid data for SSSlideInfoAtom at offset 6: {}", LittleEndian.getShort(_header, 6)); } _slideTime = LittleEndian.getInt(source, ofs); if (_slideTime < 0 || _slideTime > 86399000) { - LOG.atDebug().log("Invalid data for SSSlideInfoAtom - invalid slideTime: "+ _slideTime); + LOG.debug("Invalid data for SSSlideInfoAtom - invalid slideTime: {}", _slideTime); } ofs += LittleEndianConsts.INT_SIZE; _soundIdRef = LittleEndian.getInt(source, ofs); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java index 9266d798c6..5912dd23cc 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java @@ -79,7 +79,7 @@ public final class OfficeArtContent { int pos = offset; pos += drawingGroupData.fillFields(data, pos, recordFactory); if (drawingGroupData.getRecordId() == EscherRecordTypes.DGG_CONTAINER.typeID) { - LOG.atDebug().log("Invalid record-id for filling Escher records: " + drawingGroupData.getRecordId()); + LOG.debug("Invalid record-id for filling Escher records: {}", drawingGroupData.getRecordId()); } /* diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleSheet.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleSheet.java index e19332aa56..72d414ac26 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleSheet.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleSheet.java @@ -211,9 +211,9 @@ public final class StyleSheet { @Deprecated private void createPap(int istd, int nesting) { if (nesting > MAX_PAPX_NESTING) { - LOG.warn("Encountered too deep nesting, cannot fully process stylesheet at " + istd + - " with more than " + MAX_PAPX_NESTING + " nested ParagraphProperties." + - " Some data could not be parsed."); + LOG.warn("Encountered too deep nesting, cannot fully process stylesheet at {}" + + " with more than {} nested ParagraphProperties." + + " Some data could not be parsed.", istd, MAX_PAPX_NESTING); return; } @@ -268,9 +268,9 @@ public final class StyleSheet { @Deprecated private void createChp(int istd, int nesting) { if (nesting > MAX_CHPX_NESTING) { - LOG.warn("Encountered too deep nesting, cannot fully process stylesheet at " + istd + - " with more than " + MAX_CHPX_NESTING + " nested CharacterProperties." + - " Some data could not be parsed."); + LOG.warn("Encountered too deep nesting, cannot fully process stylesheet at {}" + + " with more than {} nested CharacterProperties." + + " Some data could not be parsed.", istd, MAX_CHPX_NESTING); return; } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/converter/TestWordToTextConverter.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/converter/TestWordToTextConverter.java index cb72d510f5..f33cffb433 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/converter/TestWordToTextConverter.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/converter/TestWordToTextConverter.java @@ -43,7 +43,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; public class TestWordToTextConverter { - private static final Logger LOG = LogManager.getLogger(WordToTextConverter.class); + private static final Logger LOG = LogManager.getLogger(TestWordToTextConverter.class); private static final List failingFiles = Arrays.asList( // Excel file @@ -97,13 +97,13 @@ public class TestWordToTextConverter { @ParameterizedTest @MethodSource("files") void testAllFiles(File file) throws Exception { - LOG.info("Testing " + file); + LOG.info("Testing {}", file); try (FileInputStream stream = new FileInputStream(file)) { InputStream is = FileMagic.prepareToCheckMagic(stream); FileMagic fm = FileMagic.valueOf(is); if (fm != FileMagic.OLE2) { - LOG.info("Skip non-doc file " + file); + LOG.info("Skip non-doc file {}", file); return; } diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java b/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java index bf0bc110ca..c95caca273 100644 --- a/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java +++ b/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java @@ -192,7 +192,7 @@ public class CellFormat { parts.add(new CellFormatPart(locale, valueDesc)); } catch (RuntimeException e) { - LOG.log(Level.WARN, "Invalid format: " + CellFormatter.quote(m.group()), e); + LOG.warn("Invalid format: {}", CellFormatter.quote(m.group()), e); parts.add(null); } } diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java b/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java index 879884d4a5..8a0232bb4f 100644 --- a/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java +++ b/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java @@ -256,7 +256,7 @@ public class CellFormatPart { return null; Color c = NAMED_COLORS.get(cdesc); if (c == null) { - LOG.warn("Unknown color: " + quote(cdesc)); + LOG.warn("Unknown color: {}", quote(cdesc)); } return c; } -- 2.39.5