diff options
author | Marius Volkhart <mariusvolkhart@apache.org> | 2021-02-21 20:57:25 +0000 |
---|---|---|
committer | Marius Volkhart <mariusvolkhart@apache.org> | 2021-02-21 20:57:25 +0000 |
commit | 259c9967efb354a0feff2a861ac8bd20582b6562 (patch) | |
tree | ba76a4f20503d97e77bdf18146d59e00a2369fb9 /src/scratchpad | |
parent | 6d10f26718f84591671d7cafdcc009345b9c777e (diff) | |
download | poi-259c9967efb354a0feff2a861ac8bd20582b6562.tar.gz poi-259c9967efb354a0feff2a861ac8bd20582b6562.zip |
[bug-63046] Use Log4j 2 for logging
This removes the POILogger and POILogFactory mechanism for logging. This mechanism was created at a time when the Java landscape looked very different than it does today.
Log4j 2 is an Apache Foundation project that is well maintained and is widely regarded as having good performance and capabilities. We use only the Log4j API artifact. This lets application developers choose how they want to capture logging events if at all. Integrations with Log4j 2 Core and Logback are available from the Log4j project.
Closes #224
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886770 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
99 files changed, 691 insertions, 765 deletions
diff --git a/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java b/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java index 30936c4690..70da34747b 100644 --- a/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java +++ b/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java @@ -24,6 +24,8 @@ import java.io.InputStream; import java.util.List; import java.util.stream.StreamSupport; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.extractor.ExtractorProvider; import org.apache.poi.extractor.POIOLE2TextExtractor; @@ -46,19 +48,17 @@ import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.sl.extractor.SlideShowExtractor; import org.apache.poi.sl.usermodel.SlideShowFactory; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Scratchpad-specific logic for {@link ExtractorFactory} and - * {@link org.apache.poi.extractor.ExtractorFactory}, which permit the other two to run with + * {@link ExtractorFactory}, which permit the other two to run with * no Scratchpad jar (though without functionality!) * <p>Note - should not be used standalone, always use via the other * two classes</p> */ @SuppressWarnings("WeakerAccess") public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { - private static final POILogger LOG = POILogFactory.getLogger(OLE2ScratchpadExtractorFactory.class); + private static final Logger LOG = LogManager.getLogger(OLE2ScratchpadExtractorFactory.class); @Override public boolean accepts(FileMagic fm) { @@ -169,7 +169,7 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { .filter(entry -> entry.getName().startsWith("_")) .forEach(dirs::add); } catch(FileNotFoundException e) { - LOG.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage()); + LOG.atInfo().withThrowable(e).log("Ignoring FileNotFoundException while extracting Word document"); // ignored here } //} else if(ext instanceof PowerPointExtractor) { diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java index ef9d42b412..6ccc5a6797 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java @@ -19,17 +19,19 @@ package org.apache.poi.hdgf.chunks; import java.util.ArrayList; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hdgf.chunks.ChunkFactory.CommandDefinition; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * Base of all chunks, which hold data, flags etc */ public final class Chunk { /** For logging warnings about the structure of the file */ - private static final POILogger LOG = POILogFactory.getLogger(Chunk.class); + private static final Logger LOG = LogManager.getLogger(Chunk.class); /** * The contents of the chunk, excluding the header, @@ -179,9 +181,7 @@ public final class Chunk { // Check we seem to have enough data if(offset >= contents.length) { - LOG.log(POILogger.WARN, - "Command offset ", offset, " past end of data at ", contents.length - ); + LOG.atWarn().log("Command offset {} past end of data at {}", box(offset),box(contents.length)); continue; } @@ -241,12 +241,11 @@ public final class Chunk { break; default: - LOG.log(POILogger.INFO, - "Command of type ", type, " not processed!"); + LOG.atInfo().log("Command of type {} not processed!", box(type)); } } catch (Exception e) { - LOG.log(POILogger.ERROR, "Unexpected error processing command, ignoring and continuing. Command: ", command, e); + LOG.atError().withThrowable(e).log("Unexpected error processing command, ignoring and continuing. Command: {}", command); } // Add to the array diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index 6bf22a02d7..76b5937338 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -26,10 +26,12 @@ import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * Factor class to create the appropriate chunks, which @@ -59,7 +61,7 @@ public final class ChunkFactory { "/org/apache/poi/hdgf/chunks_parse_cmds.tbl"; /** For logging problems we spot with the file */ - private static final POILogger LOG = POILogFactory.getLogger(ChunkFactory.class); + private static final Logger LOG = LogManager.getLogger(ChunkFactory.class); public ChunkFactory(int version) throws IOException { this.version = version; @@ -139,8 +141,7 @@ public final class ChunkFactory { // Check we have enough data, and tweak the header size // as required if(endOfDataPos > data.length) { - LOG.log(POILogger.WARN, - "Header called for ", header.getLength(), " bytes, but that would take us past the end of the data!"); + LOG.atWarn().log("Header called for {} bytes, but that would take us past the end of the data!", box(header.getLength())); endOfDataPos = data.length; header.setLength(data.length - offset - header.getSizeInBytes()); @@ -165,7 +166,7 @@ public final class ChunkFactory { data, endOfDataPos); endOfDataPos += 8; } else { - LOG.log(POILogger.ERROR, "Header claims a length to ", endOfDataPos, " there's then no space for the trailer in the data (", data.length, ")"); + LOG.atError().log("Header claims a length to {} there's then no space for the trailer in the data ({})", box(endOfDataPos),box(data.length)); } } if(header.hasSeparator()) { @@ -173,7 +174,7 @@ public final class ChunkFactory { separator = new ChunkSeparator( data, endOfDataPos); } else { - LOG.log(POILogger.ERROR, "Header claims a length to ", endOfDataPos, " there's then no space for the separator in the data (", data.length, ")"); + LOG.atError().log("Header claims a length to {} there's then no space for the separator in the data ({})", box(endOfDataPos),box(data.length)); } } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java index dc923c588d..b977483473 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java @@ -19,15 +19,17 @@ package org.apache.poi.hdgf.streams; import java.util.ArrayList; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hdgf.chunks.Chunk; import org.apache.poi.hdgf.chunks.ChunkFactory; import org.apache.poi.hdgf.chunks.ChunkHeader; import org.apache.poi.hdgf.pointers.Pointer; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; public final class ChunkStream extends Stream { - private static final POILogger LOG = POILogFactory.getLogger(ChunkStream.class); + private static final Logger LOG = LogManager.getLogger(ChunkStream.class); private final ChunkFactory chunkFactory; /** All the Chunks we contain */ @@ -66,14 +68,14 @@ public final class ChunkStream extends Stream { pos += chunk.getOnDiskSize(); } else { - LOG.log(POILogger.WARN, "Needed ", headerSize, " bytes to create the next chunk header, but only found ", (contents.length-pos), " bytes, ignoring rest of data"); + LOG.atWarn().log("Needed {} bytes to create the next chunk header, but only found {} bytes, ignoring rest of data", box(headerSize),box(contents.length - pos)); pos = contents.length; } } } catch (Exception e) { - LOG.log(POILogger.ERROR, "Failed to create chunk at ", pos, ", ignoring rest of data." + e); + LOG.atError().withThrowable(e).log("Failed to create chunk at {}, ignoring rest of data.", box(pos)); } chunks = chunksA.toArray(new Chunk[0]); diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java index 0d42389055..443a7ee4de 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java @@ -29,6 +29,8 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hemf.draw.HemfGraphics; import org.apache.poi.hemf.draw.HemfGraphics.EmfRenderState; @@ -43,16 +45,16 @@ import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.RecordFormatException; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Contains arbitrary data */ @Internal public class HemfComment { - private static final POILogger LOG = POILogFactory.getLogger(HemfComment.class); + private static final Logger LOG = LogManager.getLogger(HemfComment.class); private static final int MAX_RECORD_LENGTH = HwmfPicture.MAX_RECORD_LENGTH; public enum HemfCommentRecordType { @@ -101,7 +103,7 @@ public class HemfComment { */ default void draw(HemfGraphics ctx) {} - default void calcBounds(Rectangle2D bounds, Rectangle2D viewport, HemfGraphics.EmfRenderState[] renderState) { } + default void calcBounds(Rectangle2D bounds, Rectangle2D viewport, EmfRenderState[] renderState) { } @Override @@ -135,7 +137,7 @@ public class HemfComment { } @Override - public void calcBounds(Rectangle2D window, Rectangle2D viewport, HemfGraphics.EmfRenderState[] renderState) { + public void calcBounds(Rectangle2D window, Rectangle2D viewport, EmfRenderState[] renderState) { data.calcBounds(window, viewport, renderState); } @@ -601,8 +603,7 @@ public class HemfComment { // some emf comments are truncated, so we don't use readFully here int readBytes = leis.read(wmfData); if (readBytes < wmfData.length) { - LOG.log(POILogger.INFO, "Emf comment with WMF: expected ", wmfData.length, - " bytes - received only ", readBytes, " bytes."); + LOG.atInfo().log("Emf comment with WMF: expected {} bytes - received only {} bytes.", box(wmfData.length),box(readBytes)); } return leis.getReadIndex()-startIdx; diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java index e70d7ca480..59d7be584d 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java @@ -23,14 +23,14 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; import org.apache.poi.hpsf.Filetime; import org.apache.poi.hsmf.datatypes.MAPIProperty; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * A pure-MAPI attribute holding a Date, which applies @@ -42,7 +42,7 @@ import org.apache.poi.util.POILogger; * @see <a href="https://msdn.microsoft.com/en-us/library/cc433490(v=exchg.80).aspx">[MS-OXPROPS]: Exchange Server Protocols Master Property List</a> */ public final class MAPIDateAttribute extends MAPIAttribute { - private static final POILogger LOG = POILogFactory.getLogger(MAPIDateAttribute.class); + private static final Logger LOG = LogManager.getLogger(MAPIDateAttribute.class); private final Date data; /** @@ -80,7 +80,7 @@ public final class MAPIDateAttribute extends MAPIAttribute { return ((MAPIDateAttribute)attr).getDate(); } - LOG.log(POILogger.WARN, "Warning, non date property found: ", attr); + LOG.atWarn().log("Warning, non date property found: {}", attr); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java index d91449e5ca..9ad7a09997 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java @@ -19,12 +19,12 @@ package org.apache.poi.hmef.attribute; import java.nio.charset.Charset; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; import org.apache.poi.hsmf.datatypes.MAPIProperty; import org.apache.poi.hsmf.datatypes.Types; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -32,7 +32,7 @@ import org.apache.poi.util.StringUtil; * to a {@link HMEFMessage} or one of its {@link Attachment}s. */ public final class MAPIStringAttribute extends MAPIAttribute { - private static final POILogger LOG = POILogFactory.getLogger(MAPIStringAttribute.class); + private static final Logger LOG = LogManager.getLogger(MAPIStringAttribute.class); private static final String CODEPAGE = "CP1252"; private final String data; @@ -77,7 +77,7 @@ public final class MAPIStringAttribute extends MAPIAttribute { return ((MAPIRtfAttribute)attr).getDataString(); } - LOG.log(POILogger.WARN, "Warning, non string property found: ", attr); + LOG.atWarn().log("Warning, non string property found: {}", attr); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java index e9f4e6e22a..1c64dbe3c1 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java @@ -26,20 +26,20 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; import org.apache.poi.hpsf.Filetime; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * A Date attribute which applies to a {@link HMEFMessage} * or one of its {@link Attachment}s. */ public final class TNEFDateAttribute extends TNEFAttribute { - private static final POILogger LOG = POILogFactory.getLogger(TNEFDateAttribute.class); + private static final Logger LOG = LogManager.getLogger(TNEFDateAttribute.class); private final Date data; /** @@ -95,7 +95,7 @@ public final class TNEFDateAttribute extends TNEFAttribute { return ((TNEFDateAttribute)attr).getDate(); } - LOG.log(POILogger.WARN, "Warning, non date property found: ", attr); + LOG.atWarn().log("Warning, non date property found: {}", attr); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java index e5e79dfebf..d42feaa51a 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java @@ -20,10 +20,10 @@ package org.apache.poi.hmef.attribute; import java.io.IOException; import java.io.InputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -31,7 +31,7 @@ import org.apache.poi.util.StringUtil; * or one of its {@link Attachment}s. */ public final class TNEFStringAttribute extends TNEFAttribute { - private static final POILogger LOG = POILogFactory.getLogger(TNEFStringAttribute.class); + private static final Logger LOG = LogManager.getLogger(TNEFStringAttribute.class); private final String data; /** @@ -78,7 +78,7 @@ public final class TNEFStringAttribute extends TNEFAttribute { return ((TNEFStringAttribute)attr).getString(); } - LOG.log(POILogger.WARN, "Warning, non string property found: ", attr); + LOG.atWarn().log("Warning, non string property found: {}", attr); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java b/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java index 4c50e690ca..6d5b67173a 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java @@ -19,6 +19,8 @@ package org.apache.poi.hpbf.model; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpbf.model.qcbits.QCBit; import org.apache.poi.hpbf.model.qcbits.QCPLCBit; import org.apache.poi.hpbf.model.qcbits.QCTextBit; @@ -27,14 +29,12 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Read Quill Contents (/Quill/QuillSub/CONTENTS) from an HPBF (Publisher .pub) document */ public final class QuillContents extends HPBFPart { - private static final POILogger LOG = POILogFactory.getLogger(QuillContents.class); + private static final Logger LOG = LogManager.getLogger(QuillContents.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 1_000_000; @@ -79,7 +79,7 @@ public final class QuillContents extends HPBFPart { bits[i] = QCPLCBit.createQCPLCBit(thingType, bitType, bitData); } catch (ArrayIndexOutOfBoundsException e) { // bug 60685: fall back so that the rest of the document can be read - LOG.log(POILogger.WARN, "Unable to read Quill Contents PLC Bit record. Ignoring this record."); + LOG.atWarn().log("Unable to read Quill Contents PLC Bit record. Ignoring this record."); bits[i] = new UnknownQCBit(thingType, bitType, bitData); } } else { diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java b/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java index cc76fefe89..33dcde3b0e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java @@ -24,18 +24,20 @@ import java.io.EOFException; import java.io.IOException; import java.util.zip.InflaterInputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.sl.image.ImageHeaderPICT; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Represents Macintosh PICT picture data. */ public final class PICT extends Metafile { - private static final POILogger LOG = POILogFactory.getLogger(PICT.class); + private static final Logger LOG = LogManager.getLogger(PICT.class); @Override @@ -85,7 +87,7 @@ public final class PICT extends Metafile { out.write(chunk, 0, lastLen); } // End of picture marker for PICT is 0x00 0xFF - LOG.log(POILogger.ERROR, "PICT zip-stream is invalid, read as much as possible. Uncompressed length of header: ", header.getWmfSize(), " / Read bytes: ", out.size(), e); + LOG.atError().withThrowable(e).log("PICT zip-stream is invalid, read as much as possible. Uncompressed length of header: {} / Read bytes: {}", box(header.getWmfSize()),box(out.size())); } return out.toByteArray(); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFMetroShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFMetroShape.java index f65d0fb178..54495aab2a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFMetroShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFMetroShape.java @@ -19,6 +19,8 @@ package org.apache.poi.hslf.model; import java.lang.reflect.Method; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherComplexProperty; import org.apache.poi.ddf.EscherPropertyTypes; @@ -26,8 +28,6 @@ import org.apache.poi.ddf.EscherTertiaryOptRecord; import org.apache.poi.hslf.usermodel.HSLFShape; import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Experimental class for metro blobs, i.e. an alternative escher property @@ -35,8 +35,8 @@ import org.apache.poi.util.POILogger; */ @Internal public class HSLFMetroShape<T extends Shape<?,?>> { - private static final POILogger LOGGER = POILogFactory.getLogger(HSLFMetroShape.class); - + private static final Logger LOGGER = LogManager.getLogger(HSLFMetroShape.class); + private final HSLFShape shape; public HSLFMetroShape(HSLFShape shape) { @@ -81,7 +81,7 @@ public class HSLFMetroShape<T extends Shape<?,?>> { Method m = ms.getMethod("parseShape", byte[].class); return (T)m.invoke(null, new Object[]{metroBytes}); } catch (Exception e) { - LOGGER.log(POILogger.ERROR, "can't process metro blob, check if all dependencies for POI OOXML are in the classpath.", e); + LOGGER.atError().withThrowable(e).log("can't process metro blob, check if all dependencies for POI OOXML are in the classpath."); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java index 8851d6c269..17d5ea5610 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java @@ -22,9 +22,10 @@ import static org.apache.poi.util.GenericRecordUtil.getBitsAsString; import java.util.Map; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.SimpleMessage; import org.apache.poi.util.GenericRecordUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Definition of a special kind of property of some text, or its @@ -34,9 +35,9 @@ import org.apache.poi.util.POILogger; * (but related) properties */ public abstract class BitMaskTextProp extends TextProp { - protected static final POILogger LOG = POILogFactory.getLogger(BitMaskTextProp.class); + protected static final Logger LOG = LogManager.getLogger(BitMaskTextProp.class); - private String[] subPropNames; + private String[] subPropNames; private int[] subPropMasks; private boolean[] subPropMatches; @@ -148,8 +149,8 @@ public abstract class BitMaskTextProp extends TextProp { setWriteMask(writeMask); super.setValue(maskValue(val)); if (val != super.getValue()) { - LOG.log(POILogger.WARN, "Style properties of '", getName(), "' don't match mask - output will be sanitized"); - if (LOG.check(POILogger.DEBUG)) { + LOG.atWarn().log("Style properties of '{}' don't match mask - output will be sanitized", getName()); + LOG.atDebug().log(() -> { StringBuilder sb = new StringBuilder("The following style attributes of the '") .append(getName()).append("' property will be ignored:\n"); int i=0; @@ -159,8 +160,8 @@ public abstract class BitMaskTextProp extends TextProp { } i++; } - LOG.log(POILogger.DEBUG, sb.toString()); - } + return new SimpleMessage(sb); + }); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java index 2e51499c8f..9155731dcd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java @@ -29,13 +29,14 @@ import java.util.Map; import java.util.Objects; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.Duplicatable; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hslf.exceptions.HSLFException; +import org.apache.poi.hslf.record.Record; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * For a given run of characters, holds the properties (which could @@ -44,7 +45,7 @@ import org.apache.poi.util.POILogger; * properties, and the indent level if required. */ public class TextPropCollection implements GenericRecord, Duplicatable { - private static final POILogger LOG = POILogFactory.getLogger(TextPropCollection.class); + private static final Logger LOG = LogManager.getLogger(TextPropCollection.class); /** All the different kinds of paragraph properties we might handle */ private static final TextProp[] paragraphTextPropTypes = { @@ -291,12 +292,12 @@ public class TextPropCollection implements GenericRecord, Duplicatable { if (!isMasterStyle) { // First goes the number of characters we affect // MasterStyles don't have this field - org.apache.poi.hslf.record.Record.writeLittleEndian(charactersCovered,o); + Record.writeLittleEndian(charactersCovered,o); } // Then we have the indentLevel field if it's a paragraph collection if (textPropType == TextPropType.paragraph && indentLevel > -1) { - org.apache.poi.hslf.record.Record.writeLittleEndian(indentLevel, o); + Record.writeLittleEndian(indentLevel, o); } // Then the mask field @@ -304,7 +305,7 @@ public class TextPropCollection implements GenericRecord, Duplicatable { for (TextProp textProp : textProps.values()) { mask |= textProp.getWriteMask(); } - org.apache.poi.hslf.record.Record.writeLittleEndian(mask,o); + Record.writeLittleEndian(mask,o); // Then the contents of all the properties for (TextProp textProp : getTextPropList()) { @@ -313,9 +314,9 @@ public class TextPropCollection implements GenericRecord, Duplicatable { // don't add empty properties, as they can't be recognized while reading continue; } else if (textProp.getSize() == 2) { - org.apache.poi.hslf.record.Record.writeLittleEndian((short)val,o); + Record.writeLittleEndian((short)val,o); } else if (textProp.getSize() == 4) { - org.apache.poi.hslf.record.Record.writeLittleEndian(val,o); + Record.writeLittleEndian(val,o); } else if (textProp instanceof HSLFTabStopPropCollection) { ((HSLFTabStopPropCollection)textProp).writeProperty(o); } @@ -383,7 +384,7 @@ public class TextPropCollection implements GenericRecord, Duplicatable { byte[] b = baos.toByteArray(); out.append(HexDump.dump(b, 0, 0)); } catch (IOException e ) { - LOG.log(POILogger.ERROR, "can't dump TextPropCollection", e); + LOG.atError().withThrowable(e).log("can't dump TextPropCollection"); } return out.toString(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java index ded20953dd..9bf2bf789f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java @@ -22,7 +22,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * A container record that specifies information about animation information for a shape. @@ -55,10 +56,11 @@ public final class AnimationInfo extends RecordContainer { private void findInterestingChildren() { // First child should be the ExMediaAtom - if(_children[0] instanceof AnimationInfoAtom) { - animationAtom = (AnimationInfoAtom)_children[0]; + final Record child = _children[0]; + if(child instanceof AnimationInfoAtom) { + animationAtom = (AnimationInfoAtom) child; } else { - LOG.log(POILogger.ERROR, "First child record wasn't a AnimationInfoAtom, was of type ", _children[0].getRecordType()); + LOG.atError().log("First child record wasn't a AnimationInfoAtom, was of type {}", box(child.getRecordType())); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java index 9f12084e15..69c8d2181f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java @@ -22,7 +22,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * This class represents a comment on a slide, in the format used by @@ -129,7 +130,7 @@ public final class Comment2000 extends RecordContainer { } else if (r instanceof Comment2000Atom){ commentAtom = (Comment2000Atom)r; } else { - LOG.log(POILogger.WARN, "Unexpected record with type=", r.getRecordType(), " in Comment2000: ", r.getClass().getName()); + LOG.atWarn().log("Unexpected record with type={} in Comment2000: {}", box(r.getRecordType()),r.getClass().getName()); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java index d3793ce15c..ebb3fc01b9 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.record; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP95_DOCUMENT; import java.io.ByteArrayInputStream; @@ -28,6 +29,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; import org.apache.poi.poifs.filesystem.DirectoryNode; @@ -35,8 +38,6 @@ import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -46,7 +47,7 @@ import org.apache.poi.util.StringUtil; */ public class CurrentUserAtom { - private static final POILogger LOG = POILogFactory.getLogger(CurrentUserAtom.class); + private static final Logger LOG = LogManager.getLogger(CurrentUserAtom.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 1_000_000; @@ -177,7 +178,7 @@ public class CurrentUserAtom long usernameLen = LittleEndian.getUShort(_contents,20); if(usernameLen > 512) { // Handle the case of it being garbage - LOG.log(POILogger.WARN, "Warning - invalid username length ", usernameLen, " found, treating as if there was no username set"); + LOG.atWarn().log("Invalid username length {} found, treating as if there was no username set", box(usernameLen)); usernameLen = 0; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java index 007c83f9f6..73489a9d2f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java @@ -22,7 +22,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; -import org.apache.poi.util.POILogger; +import static org.apache.logging.log4j.util.Unbox.box; /** * Master container for Document. There is one of these for every @@ -161,10 +161,10 @@ public final class Document extends PositionDependentRecordContainer // (normally it's 2, or 3 if you have notes) // Complain if it's not if(slwtcount == 0) { - LOG.log(POILogger.WARN, "No SlideListWithText's found - there should normally be at least one!"); + LOG.atWarn().log("No SlideListWithText's found - there should normally be at least one!"); } if(slwtcount > 3) { - LOG.log(POILogger.WARN, "Found ", slwtcount, " SlideListWithTexts - normally there should only be three!"); + LOG.atWarn().log("Found {} SlideListWithTexts - normally there should only be three!", box(slwtcount)); } // Now grab all the SLWTs diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java index 7cb1caa894..f9443b85d0 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java @@ -22,7 +22,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * This data represents an embedded object in the document. @@ -102,17 +103,19 @@ public class ExEmbed extends RecordContainer { private void findInterestingChildren() { // First child should be the ExHyperlinkAtom - if(_children[0] instanceof ExEmbedAtom) { - embedAtom = (ExEmbedAtom)_children[0]; + Record child = _children[0]; + if(child instanceof ExEmbedAtom) { + embedAtom = (ExEmbedAtom) child; } else { - LOG.log(POILogger.ERROR, "First child record wasn't a ExEmbedAtom, was of type ", _children[0].getRecordType()); + LOG.atError().log("First child record wasn't a ExEmbedAtom, was of type {}", box(child.getRecordType())); } // Second child should be the ExOleObjAtom - if (_children[1] instanceof ExOleObjAtom) { - oleObjAtom = (ExOleObjAtom)_children[1]; + child = _children[1]; + if (child instanceof ExOleObjAtom) { + oleObjAtom = (ExOleObjAtom) child; } else { - LOG.log(POILogger.ERROR, "Second child record wasn't a ExOleObjAtom, was of type ", _children[1].getRecordType()); + LOG.atError().log("Second child record wasn't a ExOleObjAtom, was of type {}", box(child.getRecordType())); } for (int i = 2; i < _children.length; i++) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java index eeb260cf1a..945a8df41b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java @@ -21,7 +21,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * This class represents the data of a link in the document. @@ -115,18 +116,20 @@ public class ExHyperlink extends RecordContainer { private void findInterestingChildren() { // First child should be the ExHyperlinkAtom - if(_children[0] instanceof ExHyperlinkAtom) { - linkAtom = (ExHyperlinkAtom)_children[0]; + Record child = _children[0]; + if(child instanceof ExHyperlinkAtom) { + linkAtom = (ExHyperlinkAtom) child; } else { - LOG.log(POILogger.ERROR, "First child record wasn't a ExHyperlinkAtom, was of type ", _children[0].getRecordType()); + LOG.atError().log("First child record wasn't a ExHyperlinkAtom, was of type {}", box(child.getRecordType())); } for (int i = 1; i < _children.length; i++) { - if (_children[i] instanceof CString){ - if ( linkDetailsA == null) linkDetailsA = (CString)_children[i]; - else linkDetailsB = (CString)_children[i]; + child = _children[i]; + if (child instanceof CString){ + if ( linkDetailsA == null) linkDetailsA = (CString) child; + else linkDetailsB = (CString) child; } else { - LOG.log(POILogger.ERROR, "Record after ExHyperlinkAtom wasn't a CString, was of type ", _children[1].getRecordType()); + LOG.atError().log("Record after ExHyperlinkAtom wasn't a CString, was of type {}", box(child.getRecordType())); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java index e1f9375184..81654dfded 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java @@ -22,7 +22,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * A container record that specifies information about a movie stored externally. @@ -69,10 +70,11 @@ public class ExMCIMovie extends RecordContainer { // TODO - instantiable supercl private void findInterestingChildren() { // First child should be the ExVideoContainer - if (_children[0] instanceof ExVideoContainer) { - exVideo = (ExVideoContainer) _children[0]; + final Record child = _children[0]; + if (child instanceof ExVideoContainer) { + exVideo = (ExVideoContainer) child; } else { - LOG.log(POILogger.ERROR, "First child record wasn't a ExVideoContainer, was of type ", _children[0].getRecordType()); + LOG.atError().log("First child record wasn't a ExVideoContainer, was of type {}", box(child.getRecordType())); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java index 3787a99860..c6935e84dd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java @@ -22,7 +22,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * A container record that specifies information about external video data. @@ -57,15 +58,17 @@ public final class ExVideoContainer extends RecordContainer { private void findInterestingChildren() { // First child should be the ExMediaAtom - if(_children[0] instanceof ExMediaAtom) { - mediaAtom = (ExMediaAtom)_children[0]; + Record child = _children[0]; + if(child instanceof ExMediaAtom) { + mediaAtom = (ExMediaAtom) child; } else { - LOG.log(POILogger.ERROR, "First child record wasn't a ExMediaAtom, was of type ", _children[0].getRecordType()); + LOG.atError().log("First child record wasn't a ExMediaAtom, was of type {}", box(child.getRecordType())); } - if(_children[1] instanceof CString) { - pathAtom = (CString)_children[1]; + child = _children[1]; + if(child instanceof CString) { + pathAtom = (CString) child; } else { - LOG.log(POILogger.ERROR, "Second child record wasn't a CString, was of type ", _children[1].getRecordType()); + LOG.atError().log("Second child record wasn't a CString, was of type {}", box(child.getRecordType())); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java index c3e17e89db..665824fcc8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java @@ -35,7 +35,6 @@ import org.apache.poi.common.usermodel.fonts.FontPitch; import org.apache.poi.hslf.usermodel.HSLFFontInfo; import org.apache.poi.hslf.usermodel.HSLFFontInfoPredefined; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogger; /** * {@code FontCollection} ia a container that holds information @@ -62,7 +61,7 @@ public final class FontCollection extends RecordContainer { HSLFFontInfo fi = addFont(fontHeader); fi.addFacet(fed); } else { - LOG.log(POILogger.WARN, "Warning: FontCollection child wasn't a FontEntityAtom, was ", r.getClass().getSimpleName()); + LOG.atWarn().log("FontCollection child wasn't a FontEntityAtom, was {}", r.getClass().getSimpleName()); } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java index ff4eaf478f..2c1bd86229 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java @@ -22,7 +22,8 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * A container record that specifies information about the footers on a presentation slide. @@ -89,11 +90,11 @@ public final class HeadersFootersContainer extends RecordContainer { csFooter = cs; break; default: - LOG.log(POILogger.WARN, "Unexpected CString.Options in HeadersFootersContainer: ", opts); + LOG.atWarn().log("Unexpected CString.Options in HeadersFootersContainer: {}", box(opts)); break; } } else { - LOG.log(POILogger.WARN, "Unexpected record in HeadersFootersContainer: ", child); + LOG.atWarn().log("Unexpected record in HeadersFootersContainer: {}", child); } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java index 53cf4639ed..38b0c6ecc9 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java @@ -21,7 +21,6 @@ import java.io.OutputStream; import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; /** * This class represents the metadata of a link in a slide/notes/etc. @@ -61,7 +60,7 @@ public class InteractiveInfo extends RecordContainer { private void findInterestingChildren() { // First child should be the InteractiveInfoAtom if (_children == null || _children.length == 0 || !(_children[0] instanceof InteractiveInfoAtom)) { - LOG.log(POILogger.WARN, "First child record wasn't a InteractiveInfoAtom - leaving this atom in an invalid state..."); + LOG.atWarn().log("First child record wasn't a InteractiveInfoAtom - leaving this atom in an invalid state..."); return; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java index 82cc9e13ac..1e3cf364a4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java @@ -31,7 +31,6 @@ import org.apache.poi.hslf.model.textproperties.IndentProp; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; /** * Specifies the Indent Level for the text @@ -85,7 +84,7 @@ public final class MasterTextPropAtom extends RecordAtom { try { read(); } catch (Exception e){ - LOG.log(POILogger.ERROR, "Failed to parse MasterTextPropAtom", e); + LOG.atError().withThrowable(e).log("Failed to parse MasterTextPropAtom"); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java index bb55a91eef..de65b231d2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java @@ -48,7 +48,8 @@ import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * These are actually wrappers onto Escher drawings. Make use of @@ -201,7 +202,7 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord // Wind on int size = r.getRecordSize(); if(size < 8) { - LOG.log(POILogger.WARN, "Hit short DDF record at ", startPos, " - ", size); + LOG.atWarn().log("Hit short DDF record at {} - {}", box(startPos),box(size)); } /* @@ -211,7 +212,7 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord * Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size. */ if(size != escherBytes){ - LOG.log(POILogger.WARN, "Record length=", escherBytes, " but getRecordSize() returned ", r.getRecordSize(), "; record: ", r.getClass()); + LOG.atWarn().log("Record length={} but getRecordSize() returned {}; record: {}", box(escherBytes),box(r.getRecordSize()),r.getClass()); size = escherBytes; } startPos += size; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java index 2b3f5eef9b..1ee2403cf7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -35,7 +35,6 @@ import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; /** * General holder for PersistPtrFullBlock and PersistPtrIncrementalBlock @@ -176,8 +175,9 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom if (newPos == null) { Integer id = me.getKey(); - LOG.log(POILogger.WARN, "Couldn't find the new location of the \"slide\" with id " + id + " that used to be at " + oldPos); - LOG.log(POILogger.WARN, "Not updating the position of it, you probably won't be able to find it any more (if you ever could!)"); + LOG.atWarn().log("Couldn't find the new location of the \"slide\" with id {} that used to " + + "be at {}. Not updating the position of it, you probably won't be able to find it any more " + + "(if you ever could!)", id, oldPos); } else { me.setValue(newPos); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index dba30ed230..2b06b4d7c3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -23,13 +23,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.record.RecordTypes.RecordConstructor; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * This abstract class represents a record in the PowerPoint document. @@ -42,7 +44,7 @@ import org.apache.poi.util.POILogger; public abstract class Record implements GenericRecord { // For logging - protected static final POILogger LOG = POILogFactory.getLogger(Record.class); + protected static final Logger LOG = LogManager.getLogger(Record.class); /** * Is this record type an Atom record (only has data), @@ -79,7 +81,7 @@ public abstract class Record implements GenericRecord } @Override - public List<org.apache.poi.hslf.record.Record> getGenericChildren() { + public List<Record> getGenericChildren() { Record[] recs = getChildRecords(); return (recs == null) ? null : Arrays.asList(recs); } @@ -107,7 +109,7 @@ public abstract class Record implements GenericRecord * @param b The byte array to build from * @param offset The offset to build at */ - public static org.apache.poi.hslf.record.Record buildRecordAtOffset(byte[] b, int offset) { + public static Record buildRecordAtOffset(byte[] b, int offset) { long type = LittleEndian.getUShort(b,offset+2); long rlen = LittleEndian.getUInt(b,offset+4); @@ -122,7 +124,7 @@ public abstract class Record implements GenericRecord * Default method for finding child records of a container record */ public static Record[] findChildRecords(byte[] b, int start, int len) { - List<org.apache.poi.hslf.record.Record> children = new ArrayList<>(5); + List<Record> children = new ArrayList<>(5); // Jump our little way along, creating records as we go int pos = start; @@ -149,7 +151,7 @@ public abstract class Record implements GenericRecord } // Turn the vector into an array, and return - return children.toArray(new org.apache.poi.hslf.record.Record[0]); + return children.toArray(new Record[0]); } /** @@ -161,7 +163,7 @@ public abstract class Record implements GenericRecord * (not including the size of the header), this code assumes you're * passing in corrected lengths */ - public static org.apache.poi.hslf.record.Record createRecordForType(long type, byte[] b, int start, int len) { + public static Record createRecordForType(long type, byte[] b, int start, int len) { // We use the RecordTypes class to provide us with the right // class to use for a given type // A spot of reflection gets us the (byte[],int,int) constructor @@ -183,7 +185,7 @@ public abstract class Record implements GenericRecord // Handle case of a corrupt last record, whose claimed length // would take us passed the end of the file if(start + len > b.length ) { - LOG.log(POILogger.WARN, "Warning: Skipping record of type " + type + " at position " + start + " which claims to be longer than the file! (" + len + " vs " + (b.length-start) + ")"); + LOG.atWarn().log("Warning: Skipping record of type {} at position {} which claims to be longer than the file! ({} vs {})", type, box(start), box(len), box(b.length - start)); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java b/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java index 41c97a934d..2df455bd9e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; -import org.apache.poi.util.POILogger; +import static org.apache.logging.log4j.util.Unbox.box; /** * A container holding information about a sound. It contains: @@ -65,17 +65,19 @@ public final class Sound extends RecordContainer { private void findInterestingChildren() { // First child should be the ExHyperlinkAtom - if(_children[0] instanceof CString) { - _name = (CString)_children[0]; + Record child = _children[0]; + if(child instanceof CString) { + _name = (CString) child; } else { - LOG.log(POILogger.ERROR, "First child record wasn't a CString, was of type ", _children[0].getRecordType()); + LOG.atError().log("First child record wasn't a CString, was of type {}", box(child.getRecordType())); } // Second child should be the ExOleObjAtom - if (_children[1] instanceof CString) { - _type = (CString)_children[1]; + child = _children[1]; + if (child instanceof CString) { + _type = (CString) child; } else { - LOG.log(POILogger.ERROR, "Second child record wasn't a CString, was of type ", _children[1].getRecordType()); + LOG.atError().log("Second child record wasn't a CString, was of type {}", box(child.getRecordType())); } for (int i = 2; i < _children.length; i++) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index fe9e11fcbe..de2b28c311 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -33,7 +33,8 @@ import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.HexDump; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * A StyleTextPropAtom (type 4001). Holds basic character properties @@ -251,7 +252,7 @@ public final class StyleTextPropAtom extends RecordAtom { } if (rawContents.length > 0 && textHandled != (size+1)){ - LOG.log(POILogger.WARN, "Problem reading paragraph style runs: textHandled = ", textHandled, ", text.size+1 = ", (size+1)); + LOG.atWarn().log("Problem reading paragraph style runs: textHandled = {}, text.size+1 = {}", box(textHandled),box(size + 1)); } // Now do the character stylings @@ -283,7 +284,7 @@ public final class StyleTextPropAtom extends RecordAtom { } } if (rawContents.length > 0 && textHandled != (size+1)){ - LOG.log(POILogger.WARN, "Problem reading character style runs: textHandled = ", textHandled, ", text.size+1 = ", (size+1)); + LOG.atWarn().log("Problem reading character style runs: textHandled = {}, text.size+1 = {}", box(textHandled),box(size + 1)); } // Handle anything left over @@ -296,8 +297,7 @@ public final class StyleTextPropAtom extends RecordAtom { private int checkTextLength(int readLength, int handledSoFar, int overallSize) { if (readLength + handledSoFar > overallSize + 1) { - LOG.log(POILogger.WARN, "Style length of ", readLength, " at ", handledSoFar, - " larger than stated size of ", overallSize, ", truncating"); + LOG.atWarn().log("Style length of {} at {} larger than stated size of {}, truncating", box(readLength),box(handledSoFar),box(overallSize)); return overallSize + 1 - handledSoFar; } return readLength; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java index 9ca6644789..5de317cc0c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java @@ -36,7 +36,6 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianOutputStream; -import org.apache.poi.util.POILogger; /** * Ruler of a text as it differs from the style's ruler settings. @@ -98,7 +97,7 @@ public final class TextRulerAtom extends RecordAtom { // Get the record data. read(leis); } catch (IOException e){ - LOG.log(POILogger.ERROR, "Failed to parse TextRulerAtom: ", e.getMessage()); + LOG.atError().withThrowable(e).log("Failed to parse TextRulerAtom"); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java index 40a85fab1c..a396cd95bf 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType; @@ -35,8 +37,6 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianOutputStream; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * TxMasterStyleAtom atom (4003). @@ -53,7 +53,7 @@ import org.apache.poi.util.POILogger; * </p> */ public final class TxMasterStyleAtom extends RecordAtom { - private static final POILogger LOG = POILogFactory.getLogger(TxMasterStyleAtom.class); + private static final Logger LOG = LogManager.getLogger(TxMasterStyleAtom.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; @@ -79,7 +79,7 @@ public final class TxMasterStyleAtom extends RecordAtom { try { init(); } catch (Exception e){ - LOG.log(POILogger.WARN, "Exception when reading available styles", e); + LOG.atWarn().withThrowable(e).log("Exception when reading available styles"); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java index 88a90cbba0..c02561d8c7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java @@ -26,6 +26,8 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.Iterator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherArrayProperty; import org.apache.poi.ddf.EscherContainerRecord; @@ -47,8 +49,6 @@ import org.apache.poi.ss.usermodel.ShapeTypes; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Represents an AutoShape.<p> @@ -57,7 +57,7 @@ import org.apache.poi.util.POILogger; * See {@link ShapeTypes} */ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFAutoShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFAutoShape.class); static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40}; static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC}; @@ -218,11 +218,11 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape, //sanity check if(verticesProp == null) { - LOG.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES "); + LOG.atWarn().log("Freeform is missing GEOMETRY__VERTICES "); return super.getGeometry(); } if(segmentsProp == null) { - LOG.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO "); + LOG.atWarn().log("Freeform is missing GEOMETRY__SEGMENTINFO "); return super.getGeometry(); } @@ -236,7 +236,7 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape, while (segIter.hasNext()) { byte[] segElem = segIter.next(); - HSLFAutoShape.PathInfo pi = getPathInfo(segElem); + PathInfo pi = getPathInfo(segElem); if (pi == null) { continue; } @@ -368,7 +368,7 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape, } private static void handleEscapeInfo(Path pathCT, Path2D path2D, byte[] segElem, Iterator<byte[]> vertIter) { - HSLFAutoShape.EscapeInfo ei = getEscapeInfo(segElem); + EscapeInfo ei = getEscapeInfo(segElem); if (ei == null) { return; } @@ -466,26 +466,26 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape, return new Point2D.Double(xyPoints[0],xyPoints[1]); } - private static HSLFAutoShape.PathInfo getPathInfo(byte[] elem) { + private static PathInfo getPathInfo(byte[] elem) { int elemUS = LittleEndian.getUShort(elem, 0); int pathInfo = PATH_INFO.getValue(elemUS); - return HSLFAutoShape.PathInfo.valueOf(pathInfo); + return PathInfo.valueOf(pathInfo); } - private static HSLFAutoShape.EscapeInfo getEscapeInfo(byte[] elem) { + private static EscapeInfo getEscapeInfo(byte[] elem) { int elemUS = LittleEndian.getUShort(elem, 0); int escInfo = ESCAPE_INFO.getValue(elemUS); - return HSLFAutoShape.EscapeInfo.valueOf(escInfo); + return EscapeInfo.valueOf(escInfo); } private static AdjustPoint fillPoint(byte[] xyMaster, int[] xyPoints) { if (xyMaster == null || xyPoints == null) { - LOG.log(POILogger.WARN, "Master bytes or points not set - ignore point"); + LOG.atWarn().log("Master bytes or points not set - ignore point"); return null; } if ((xyMaster.length != 4 && xyMaster.length != 8) || xyPoints.length != 2) { - LOG.log(POILogger.WARN, "Invalid number of master bytes for a single point - ignore point"); + LOG.atWarn().log("Invalid number of master bytes for a single point - ignore point"); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java index ce45fdfe9d..7fa9323209 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherArrayProperty; import org.apache.poi.ddf.EscherBSERecord; @@ -41,19 +43,20 @@ import org.apache.poi.sl.usermodel.PaintStyle; import org.apache.poi.sl.usermodel.PaintStyle.GradientPaint; import org.apache.poi.sl.usermodel.PaintStyle.GradientPaint.GradientType; import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint; +import org.apache.poi.sl.usermodel.PictureData; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Represents functionality provided by the 'Fill Effects' dialog in PowerPoint. */ @SuppressWarnings("WeakerAccess") public final class HSLFFill { - private static final POILogger LOG = POILogFactory.getLogger(HSLFFill.class); + private static final Logger LOG = LogManager.getLogger(HSLFFill.class); /** * Fill with a solid color @@ -263,7 +266,7 @@ public final class HSLFFill { case FILL_PICTURE: return getTexturePaint(); default: - LOG.log(POILogger.WARN, "unsuported fill type: ", fillType); + LOG.atWarn().log("unsupported fill type: {}", box(fillType)); return null; } } @@ -445,7 +448,7 @@ public final class HSLFFill { EscherBSERecord getEscherBSERecord(int idx){ HSLFSheet sheet = shape.getSheet(); if(sheet == null) { - LOG.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet"); + LOG.atDebug().log("Fill has not yet been assigned to a sheet"); return null; } HSLFSlideShow ppt = sheet.getSlideShow(); @@ -453,7 +456,7 @@ public final class HSLFFill { EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); if(bstore == null) { - LOG.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found "); + LOG.atDebug().log("EscherContainerRecord.BSTORE_CONTAINER was not found "); return null; } List<EscherRecord> lst = bstore.getChildRecords(); @@ -560,10 +563,10 @@ public final class HSLFFill { EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); - java.util.List<EscherRecord> lst = bstore.getChildRecords(); + List<EscherRecord> lst = bstore.getChildRecords(); int idx = p.getPropertyValue(); if (idx == 0){ - LOG.log(POILogger.WARN, "no reference to picture data found "); + LOG.atWarn().log("no reference to picture data found "); } else { EscherBSERecord bse = (EscherBSERecord)lst.get(idx - 1); for (HSLFPictureData pd : pict) { @@ -579,7 +582,7 @@ public final class HSLFFill { /** * Assign picture used to fill the underlying shape. * - * @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], org.apache.poi.sl.usermodel.PictureData.PictureType)} method. + * @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], PictureData.PictureType)} method. */ public void setPictureData(HSLFPictureData data){ AbstractEscherOptRecord opt = shape.getEscherOptRecord(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java index f3bf2dd084..0a3bcc91bb 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java @@ -25,6 +25,8 @@ import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherArrayProperty; import org.apache.poi.ddf.EscherContainerRecord; @@ -34,10 +36,10 @@ import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; +import static org.apache.logging.log4j.util.Unbox.box; + /** * A "Freeform" shape. * @@ -47,7 +49,7 @@ import org.apache.poi.util.Units; * </p> */ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFFreeformShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFFreeformShape.class); enum ShapePath { @@ -138,7 +140,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh break; case PathIterator.SEG_QUADTO: //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO - LOG.log(POILogger.WARN, "SEG_QUADTO is not supported"); + LOG.atWarn().log("SEG_QUADTO is not supported"); break; case PathIterator.SEG_CLOSE: pntInfo.add(pntInfo.get(0)); @@ -150,7 +152,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh numPoints++; break; default: - LOG.log(POILogger.WARN, "Ignoring invalid segment type ", type); + LOG.atWarn().log("Ignoring invalid segment type {}", box(type)); break; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java index 66cec7e4a6..cfa09db8a4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.EscherChildAnchorRecord; import org.apache.poi.ddf.EscherClientAnchorRecord; import org.apache.poi.ddf.EscherContainerRecord; @@ -33,8 +35,6 @@ import org.apache.poi.sl.usermodel.PictureData; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; /** @@ -42,7 +42,7 @@ import org.apache.poi.util.Units; */ public class HSLFGroupShape extends HSLFShape implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFGroupShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFGroupShape.class); /** * Create a new ShapeGroup. This constructor is used when a new shape is created. @@ -207,7 +207,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> { EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID); int x1,y1,x2,y2; if(clientAnchor == null){ - LOG.log(POILogger.INFO, "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord."); + LOG.atInfo().log("EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord."); EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID); x1 = rec.getDx1(); y1 = rec.getDy1(); @@ -230,7 +230,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> { /** * Return type of the shape. - * In most cases shape group type is {@link org.apache.poi.sl.usermodel.ShapeType#NOT_PRIMITIVE} + * In most cases shape group type is {@link ShapeType#NOT_PRIMITIVE} * * @return type of the shape. */ @@ -289,7 +289,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> { } else { // Should we do anything special with these non // Container records? - LOG.log(POILogger.ERROR, "Shape contained non container escher record, was ", r.getClass().getName()); + LOG.atError().log("Shape contained non container escher record, was {}", r.getClass().getName()); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java index f5806790a5..9377bfa439 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java @@ -20,12 +20,12 @@ package org.apache.poi.hslf.usermodel; import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hslf.model.HeadersFooters; import org.apache.poi.hslf.record.HeadersFootersContainer; import org.apache.poi.sl.usermodel.Notes; import org.apache.poi.sl.usermodel.Placeholder; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * This class represents a slide's notes in a PowerPoint Document. It @@ -36,7 +36,7 @@ import org.apache.poi.util.POILogger; */ public final class HSLFNotes extends HSLFSheet implements Notes<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFNotes.class); + private static final Logger LOG = LogManager.getLogger(HSLFNotes.class); private final List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<>(); @@ -57,7 +57,7 @@ public final class HSLFNotes extends HSLFSheet implements Notes<HSLFShape,HSLFTe } if (_paragraphs.isEmpty()) { - LOG.log(POILogger.WARN, "No text records found for notes sheet"); + LOG.atWarn().log("No text records found for notes sheet"); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java index c07323dad6..60f864188d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java @@ -25,18 +25,18 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hslf.record.ExOleObjStg; import org.apache.poi.sl.usermodel.ObjectData; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * A class that represents object data embedded in a slide show. */ public class HSLFObjectData implements ObjectData, GenericRecord { - private static final POILogger LOG = POILogFactory.getLogger(HSLFObjectData.class); - + private static final Logger LOG = LogManager.getLogger(HSLFObjectData.class); + /** * The record that contains the object data. */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectShape.java index af850ecd83..344e038374 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectShape.java @@ -22,6 +22,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherPropertyTypes; import org.apache.poi.ddf.EscherSpRecord; @@ -38,15 +40,13 @@ import org.apache.poi.sl.usermodel.ObjectMetaData; import org.apache.poi.sl.usermodel.ObjectMetaData.Application; import org.apache.poi.sl.usermodel.ObjectShape; import org.apache.poi.sl.usermodel.ShapeContainer; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * A shape representing embedded OLE object. */ public final class HSLFObjectShape extends HSLFPictureShape implements ObjectShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFObjectShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFObjectShape.class); private ExEmbed _exEmbed; @@ -104,7 +104,7 @@ public final class HSLFObjectShape extends HSLFPictureShape implements ObjectSha HSLFEscherClientDataRecord cldata = getClientData(true); ExObjRefAtom uer = null; - for (org.apache.poi.hslf.record.Record r : cldata.getHSLFChildRecords()) { + for (Record r : cldata.getHSLFChildRecords()) { if (r.getRecordType() == RecordTypes.ExObjRefAtom.typeID) { uer = (ExObjRefAtom)r; break; @@ -141,7 +141,7 @@ public final class HSLFObjectShape extends HSLFPictureShape implements ObjectSha } } if (data==null) { - LOG.log(POILogger.WARN, "OLE data not found"); + LOG.atWarn().log("OLE data not found"); } return data; @@ -171,7 +171,7 @@ public final class HSLFObjectShape extends HSLFPictureShape implements ObjectSha ExObjList lst = ppt.getDocumentRecord().getExObjList(create); if(lst == null){ - LOG.log(POILogger.WARN, "ExObjList not found"); + LOG.atWarn().log("ExObjList not found"); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java index 353ff715ad..49921dc81b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java @@ -21,6 +21,8 @@ import java.awt.Insets; import java.awt.geom.Rectangle2D; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherComplexProperty; @@ -34,17 +36,17 @@ import org.apache.poi.sl.draw.DrawPictureShape; import org.apache.poi.sl.usermodel.PictureShape; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeType; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; import org.apache.poi.util.Units; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Represents a picture in a PowerPoint document. */ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFPictureShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFPictureShape.class); /** * Create a new <code>Picture</code> @@ -120,14 +122,14 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS EscherBSERecord bse = getEscherBSERecord(); if (bse == null){ - LOG.log(POILogger.ERROR, "no reference to picture data found "); + LOG.atError().log("no reference to picture data found "); } else { for (HSLFPictureData pd : pict) { if (pd.getOffset() == bse.getOffset()){ return pd; } } - LOG.log(POILogger.ERROR, "no picture found for our BSE offset ", bse.getOffset()); + LOG.atError().log("no picture found for our BSE offset {}", box(bse.getOffset())); } return null; } @@ -139,13 +141,13 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); if(bstore == null) { - LOG.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found "); + LOG.atDebug().log("EscherContainerRecord.BSTORE_CONTAINER was not found "); return null; } List<EscherRecord> lst = bstore.getChildRecords(); int idx = getPictureIndex(); if (idx == 0){ - LOG.log(POILogger.DEBUG, "picture index was not found, returning "); + LOG.atDebug().log("picture index was not found, returning "); return null; } return (EscherBSERecord)lst.get(idx-1); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java index 24011cc9aa..8fed381c38 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java @@ -23,6 +23,8 @@ import java.awt.geom.Rectangle2D; import java.util.Iterator; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherChildAnchorRecord; import org.apache.poi.ddf.EscherClientAnchorRecord; @@ -48,8 +50,6 @@ import org.apache.poi.sl.usermodel.PresetColor; import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeType; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; import org.apache.poi.util.Units; @@ -69,7 +69,7 @@ import org.apache.poi.util.Units; * <p> */ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFShape.class); /** * Either EscherSpContainer or EscheSpgrContainer record @@ -168,7 +168,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> { y2 = childRec.getDy2(); } else { if (useChildRec) { - LOG.log(POILogger.WARN, "EscherSpRecord.FLAG_CHILD is set but EscherChildAnchorRecord was not found"); + LOG.atWarn().log("EscherSpRecord.FLAG_CHILD is set but EscherChildAnchorRecord was not found"); } EscherClientAnchorRecord clientRec = getEscherChild(EscherClientAnchorRecord.RECORD_ID); x1 = clientRec.getCol1(); @@ -715,7 +715,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> { public <T extends Record> T getClientDataRecord(int recordType) { List<? extends Record> records = getClientRecords(); - if (records != null) for (org.apache.poi.hslf.record.Record r : records) { + if (records != null) for (Record r : records) { if (r.getRecordType() == recordType){ return (T)r; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java index 67896494de..b13789f843 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java @@ -19,6 +19,8 @@ package org.apache.poi.hslf.usermodel; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherClientDataRecord; import org.apache.poi.ddf.EscherContainerRecord; @@ -40,15 +42,13 @@ import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeType; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Create a <code>Shape</code> object depending on its type */ public final class HSLFShapeFactory { // For logging - private static final POILogger LOG = POILogFactory.getLogger(HSLFShapeFactory.class); + private static final Logger LOG = LogManager.getLogger(HSLFShapeFactory.class); /** * Create a new shape from the data provided. @@ -112,7 +112,7 @@ public final class HSLFShapeFactory { if (parent instanceof HSLFTable) { EscherTextboxRecord etr = spContainer.getChildById(EscherTextboxRecord.RECORD_ID); if (etr == null) { - LOG.log(POILogger.WARN, "invalid ppt - add EscherTextboxRecord to cell"); + LOG.atWarn().log("invalid ppt - add EscherTextboxRecord to cell"); etr = new EscherTextboxRecord(); etr.setRecordId(EscherTextboxRecord.RECORD_ID); etr.setOptions((short)15); @@ -153,14 +153,14 @@ public final class HSLFShapeFactory { return new HSLFFreeformShape(spContainer, parent); } - LOG.log(POILogger.INFO, "Creating AutoShape for a NotPrimitive shape"); + LOG.atInfo().log("Creating AutoShape for a NotPrimitive shape"); return new HSLFAutoShape(spContainer, parent); } @SuppressWarnings("unchecked") protected static <T extends Record> T getClientDataRecord(EscherContainerRecord spContainer, int recordType) { HSLFEscherClientDataRecord cldata = spContainer.getChildById(EscherClientDataRecord.RECORD_ID); - if (cldata != null) for (org.apache.poi.hslf.record.Record r : cldata.getHSLFChildRecords()) { + if (cldata != null) for (Record r : cldata.getHSLFChildRecords()) { if (r.getRecordType() == recordType) { return (T)r; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java index 922bbfc3f0..cc9932a61c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java @@ -19,6 +19,8 @@ package org.apache.poi.hslf.usermodel; import java.awt.Color; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherChildAnchorRecord; import org.apache.poi.ddf.EscherClientAnchorRecord; @@ -49,8 +51,6 @@ import org.apache.poi.sl.usermodel.StrokeStyle.LineCap; import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound; import org.apache.poi.sl.usermodel.StrokeStyle.LineDash; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; /** @@ -58,7 +58,7 @@ import org.apache.poi.util.Units; * This is the parent class for all primitive shapes like Line, Rectangle, etc. */ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFSimpleShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFSimpleShape.class); public static final double DEFAULT_LINE_WIDTH = 0.75; @@ -322,7 +322,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H @Override public Guide getAdjustValue(String name) { if (name == null || !name.matches("adj([1-9]|10)?")) { - LOG.log(POILogger.INFO, "Adjust value '", name, "' not supported. Using default value."); + LOG.atInfo().log("Adjust value '{}' not supported. Using default value.", name); return null; } @@ -384,7 +384,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H if (name == null) { name = (st != null) ? st.toString() : "<unknown>"; } - LOG.log(POILogger.WARN, "No preset shape definition for shapeType: "+name); + LOG.atWarn().log("No preset shape definition for shapeType: {}", name); } return geom; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index 6052a49800..908007b4c7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -33,6 +33,8 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.POIDocument; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.common.usermodel.fonts.FontInfo; @@ -61,10 +63,10 @@ import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; +import static org.apache.logging.log4j.util.Unbox.box; + /** * This class is a friendly wrapper on top of the more scary HSLFSlideShow. * @@ -79,7 +81,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh public static final String PP95_DOCUMENT = "PP40"; // For logging - private static final POILogger LOG = POILogFactory.getLogger(HSLFSlideShow.class); + private static final Logger LOG = LogManager.getLogger(HSLFSlideShow.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 10_000_000; @@ -94,7 +96,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh // Pointers to the most recent versions of the core records // (Document, Notes, Slide etc) - private org.apache.poi.hslf.record.Record[] _mostRecentCoreRecords; + private Record[] _mostRecentCoreRecords; // Lookup between the PersitPtr "sheet" IDs, and the position // in the mostRecentCoreRecords array private Map<Integer,Integer> _sheetIdToCoreRecordsLookup; @@ -125,7 +127,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh _hslfSlideShow = hslfSlideShow; // Handle Parent-aware Records - for (org.apache.poi.hslf.record.Record record : _hslfSlideShow.getRecords()) { + for (Record record : _hslfSlideShow.getRecords()) { if(record instanceof RecordContainer){ RecordContainer.handleParentAwareRecords((RecordContainer)record); } @@ -187,7 +189,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh private void findMostRecentCoreRecords() { // To start with, find the most recent in the byte offset domain Map<Integer,Integer> mostRecentByBytes = new HashMap<>(); - for (org.apache.poi.hslf.record.Record record : _hslfSlideShow.getRecords()) { + for (Record record : _hslfSlideShow.getRecords()) { if (record instanceof PersistPtrHolder) { PersistPtrHolder pph = (PersistPtrHolder) record; @@ -208,7 +210,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh // We now know how many unique special records we have, so init // the array - _mostRecentCoreRecords = new org.apache.poi.hslf.record.Record[mostRecentByBytes.size()]; + _mostRecentCoreRecords = new Record[mostRecentByBytes.size()]; // We'll also want to be able to turn the slide IDs into a position // in this array @@ -225,7 +227,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh } // Now convert the byte offsets back into record offsets - for (org.apache.poi.hslf.record.Record record : _hslfSlideShow.getRecords()) { + for (Record record : _hslfSlideShow.getRecords()) { if (!(record instanceof PositionDependentRecord)) { continue; } @@ -253,7 +255,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh } // Now look for the interesting records in there - for (org.apache.poi.hslf.record.Record record : _mostRecentCoreRecords) { + for (Record record : _mostRecentCoreRecords) { // Check there really is a record at this number if (record != null) { // Find the Document, and interesting things in it @@ -272,7 +274,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh * For a given SlideAtomsSet, return the core record, based on the refID * from the SlidePersistAtom */ - public org.apache.poi.hslf.record.Record getCoreRecordForSAS(SlideAtomsSet sas) { + public Record getCoreRecordForSAS(SlideAtomsSet sas) { SlidePersistAtom spa = sas.getSlidePersistAtom(); int refID = spa.getRefID(); return getCoreRecordForRefID(refID); @@ -285,13 +287,12 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh * @param refID * the refID */ - public org.apache.poi.hslf.record.Record getCoreRecordForRefID(int refID) { + public Record getCoreRecordForRefID(int refID) { Integer coreRecordId = _sheetIdToCoreRecordsLookup.get(refID); if (coreRecordId != null) { return _mostRecentCoreRecords[coreRecordId]; } - LOG.log(POILogger.ERROR, - "We tried to look up a reference to a core record, but there was no core ID for reference ID ", refID); + LOG.atError().log("We tried to look up a reference to a core record, but there was no core ID for reference ID {}", box(refID)); return null; } @@ -349,7 +350,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh } for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) { - org.apache.poi.hslf.record.Record r = getCoreRecordForSAS(sas); + Record r = getCoreRecordForSAS(sas); int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier(); if (r instanceof Slide) { HSLFTitleMaster master = new HSLFTitleMaster((Slide)r, sheetNo); @@ -375,20 +376,20 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh for (SlideAtomsSet notesSet : notesSLWT.getSlideAtomsSets()) { idx++; // Get the right core record - org.apache.poi.hslf.record.Record r = getCoreRecordForSAS(notesSet); + Record r = getCoreRecordForSAS(notesSet); SlidePersistAtom spa = notesSet.getSlidePersistAtom(); String loggerLoc = "A Notes SlideAtomSet at "+idx+" said its record was at refID "+spa.getRefID(); // we need to add null-records, otherwise the index references to other existing don't work anymore if (r == null) { - LOG.log(POILogger.WARN, loggerLoc+", but that record didn't exist - record ignored."); + LOG.atWarn().log("{}, but that record didn't exist - record ignored.", loggerLoc); continue; } // Ensure it really is a notes record if (!(r instanceof Notes)) { - LOG.log(POILogger.ERROR, loggerLoc, ", but that was actually a ", r); + LOG.atError().log("{}, but that was actually a {}", loggerLoc, r); continue; } @@ -416,14 +417,11 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh idx++; // Get the right core record SlidePersistAtom spa = sas.getSlidePersistAtom(); - org.apache.poi.hslf.record.Record r = getCoreRecordForSAS(sas); + Record r = getCoreRecordForSAS(sas); // Ensure it really is a slide record if (!(r instanceof Slide)) { - LOG.log(POILogger.ERROR, "A Slide SlideAtomSet at ", idx, - " said its record was at refID ", - spa.getRefID(), - ", but that was actually a ", r); + LOG.atError().log("A Slide SlideAtomSet at {} said its record was at refID {}, but that was actually a {}", box(idx),box(spa.getRefID()),r); continue; } @@ -439,7 +437,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh if (notesPos != null && 0 <= notesPos && notesPos < _notes.size()) { notes = _notes.get(notesPos); } else { - LOG.log(POILogger.ERROR, "Notes not found for noteId=", noteId); + LOG.atError().log("Notes not found for noteId={}", box(noteId)); } } @@ -499,7 +497,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh * Returns an array of the most recent version of all the interesting * records */ - public org.apache.poi.hslf.record.Record[] getMostRecentCoreRecords() { + public Record[] getMostRecentCoreRecords() { return _mostRecentCoreRecords; } @@ -618,13 +616,13 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh _slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber); _slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber); - ArrayList<org.apache.poi.hslf.record.Record> lst = new ArrayList<>(); + ArrayList<Record> lst = new ArrayList<>(); for (SlideAtomsSet s : sas) { lst.add(s.getSlidePersistAtom()); lst.addAll(Arrays.asList(s.getSlideRecords())); } - org.apache.poi.hslf.record.Record[] r = lst.toArray(new org.apache.poi.hslf.record.Record[0]); + Record[] r = lst.toArray(new Record[0]); slwt.setChildRecord(r); } @@ -653,7 +651,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh } SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); - List<org.apache.poi.hslf.record.Record> records = new ArrayList<>(); + List<Record> records = new ArrayList<>(); List<SlideAtomsSet> sa = new ArrayList<>(Arrays.asList(sas)); HSLFSlide removedSlide = _slides.remove(index); @@ -673,7 +671,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh _documentRecord.removeSlideListWithText(slwt); } else { slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[0])); - slwt.setChildRecord(records.toArray(new org.apache.poi.hslf.record.Record[0])); + slwt.setChildRecord(records.toArray(new Record[0])); } // if the removed slide had notes - remove references to them too @@ -697,7 +695,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh if (!na.isEmpty()) { nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0])); - nslwt.setChildRecord(records.toArray(new org.apache.poi.hslf.record.Record[0])); + nslwt.setChildRecord(records.toArray(new Record[0])); } } if (na.isEmpty()) { @@ -759,8 +757,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh // Add in to the list of Slides _slides.add(slide); - LOG.log(POILogger.INFO, "Added slide ", _slides.size(), " with ref ", sp.getRefID(), - " and identifier ", sp.getSlideIdentifier()); + LOG.atInfo().log("Added slide {} with ref {} and identifier {}", box(_slides.size()),box(sp.getRefID()),box(sp.getSlideIdentifier())); // Add the core records for this new Slide to the record tree Slide slideRecord = slide.getSlideRecord(); @@ -1049,7 +1046,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh ExEmbed exEmbed = new ExEmbed(); // remove unneccessary infos, so we don't need to specify the type // of the ole object multiple times - org.apache.poi.hslf.record.Record[] children = exEmbed.getChildRecords(); + Record[] children = exEmbed.getChildRecords(); exEmbed.removeChild(children[2]); exEmbed.removeChild(children[3]); exEmbed.removeChild(children[4]); @@ -1115,7 +1112,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh private int addPersistentObject(PositionDependentRecord slideRecord) { slideRecord.setLastOnDiskOffset(HSLFSlideShowImpl.UNSET_OFFSET); - _hslfSlideShow.appendRootLevelRecord((org.apache.poi.hslf.record.Record)slideRecord); + _hslfSlideShow.appendRootLevelRecord((Record)slideRecord); // For position dependent records, hold where they were and now are // As we go along, update, and hand over, to any Position Dependent @@ -1145,7 +1142,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh int slideOffset = slideRecord.getLastOnDiskOffset(); slideRecord.setLastOnDiskOffset(slideOffset); ptr.addSlideLookup(psrId, slideOffset); - LOG.log(POILogger.INFO, "New slide/object ended up at ", slideOffset); + LOG.atInfo().log("New slide/object ended up at {}", box(slideOffset)); return psrId; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java index aa5671e06e..4295712b89 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java @@ -17,6 +17,7 @@ package org.apache.poi.hslf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.hslf.usermodel.HSLFSlideShow.POWERPOINT_DOCUMENT; import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP95_DOCUMENT; import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP97_DOCUMENT; @@ -36,6 +37,8 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.POIDocument; import org.apache.poi.hpsf.PropertySet; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; @@ -60,15 +63,13 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * This class contains the main functionality for the Powerpoint file * "reader". It is only a very basic class for now */ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { - private static final POILogger LOG = POILogFactory.getLogger(HSLFSlideShowImpl.class); + private static final Logger LOG = LogManager.getLogger(HSLFSlideShowImpl.class); static final int UNSET_OFFSET = -1; @@ -82,7 +83,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { private byte[] _docstream; // Low level contents - private org.apache.poi.hslf.record.Record[] _records; + private Record[] _records; // Raw Pictures contained in the pictures stream private List<HSLFPictureData> _pictures; @@ -246,7 +247,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { _records = read(_docstream, (int) currentUser.getCurrentEditOffset()); } - private org.apache.poi.hslf.record.Record[] read(byte[] docstream, int usrOffset) throws IOException { + private Record[] read(byte[] docstream, int usrOffset) throws IOException { //sort found records by offset. //(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted) NavigableMap<Integer, Record> records = new TreeMap<>(); // offset -> record @@ -256,7 +257,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { for (Map.Entry<Integer, Record> entry : records.entrySet()) { Integer offset = entry.getKey(); - org.apache.poi.hslf.record.Record record = entry.getValue(); + Record record = entry.getValue(); Integer persistId = persistIds.get(offset); if (record == null) { // all plain records have been already added, @@ -272,7 +273,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { } decryptData.close(); - return records.values().toArray(new org.apache.poi.hslf.record.Record[0]); + return records.values().toArray(new Record[0]); } private void initRecordOffsets(byte[] docstream, int usrOffset, NavigableMap<Integer, Record> recordMap, Map<Integer, Integer> offset2id) { @@ -303,7 +304,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { int type = LittleEndian.getUShort(docstream, usrOffset + 2); int len = LittleEndian.getInt(docstream, usrOffset + 4); if (ver_inst == 0 && type == 4085 && (len == 0x1C || len == 0x20)) { - LOG.log(POILogger.WARN, "Repairing invalid user edit atom"); + LOG.atWarn().log("Repairing invalid user edit atom"); usr.setLastUserEditAtomOffset(usrOffset); } else { throw new CorruptPowerPointFileException("Powerpoint document contains invalid user edit atom"); @@ -313,7 +314,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { } public DocumentEncryptionAtom getDocumentEncryptionAtom() { - for (org.apache.poi.hslf.record.Record r : _records) { + for (Record r : _records) { if (r instanceof DocumentEncryptionAtom) { return (DocumentEncryptionAtom) r; } @@ -329,7 +330,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { try { currentUser = new CurrentUserAtom(getDirectory()); } catch (IOException ie) { - LOG.log(POILogger.ERROR, "Error finding Current User Atom", ie); + LOG.atError().withThrowable(ie).log("Error finding Current User Atom"); currentUser = new CurrentUserAtom(); } } @@ -393,14 +394,13 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { // If they type (including the bonus 0xF018) is 0, skip it PictureType pt = PictureType.forNativeID(type - 0xF018); if (pt == null) { - LOG.log(POILogger.ERROR, "Problem reading picture: Invalid image type 0, on picture with length ", imgsize, ".\nYour document will probably become corrupted if you save it!"); - LOG.log(POILogger.ERROR, "position: ", pos); + LOG.atError().log("Problem reading picture: Invalid image type 0, on picture with length {}.\nYour document will probably become corrupted if you save it! Position: {}", box(imgsize),box(pos)); } else { //The pictstream can be truncated halfway through a picture. //This is not a problem if the pictstream contains extra pictures //that are not used in any slide -- BUG-60305 if (pos + imgsize > pictstream.length) { - LOG.log(POILogger.WARN, "\"Pictures\" stream may have ended early. In some circumstances, this is not a problem; " + + LOG.atWarn().log("\"Pictures\" stream may have ended early. In some circumstances, this is not a problem; " + "in others, this could indicate a corrupt file"); break; } @@ -417,7 +417,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { pict.setIndex(_pictures.size() + 1); // index is 1-based _pictures.add(pict); } catch (IllegalArgumentException e) { - LOG.log(POILogger.ERROR, "Problem reading picture: ", e, "\nYour document will probably become corrupted if you save it!"); + LOG.atError().withThrowable(e).log("Problem reading picture. Your document will probably become corrupted if you save it!"); } } @@ -464,7 +464,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { UserEditAtom usr = null; PersistPtrHolder ptr = null; CountingOS cos = new CountingOS(); - for (org.apache.poi.hslf.record.Record record : _records) { + for (Record record : _records) { // all top level records are position dependent assert (record instanceof PositionDependentRecord); PositionDependentRecord pdr = (PositionDependentRecord) record; @@ -506,7 +506,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { } try (HSLFSlideShowEncrypted encData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom())) { - for (org.apache.poi.hslf.record.Record record : _records) { + for (Record record : _records) { assert (record instanceof PositionDependentRecord); // We've already figured out their new location, and // told them that @@ -718,7 +718,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { @SuppressWarnings({"UnusedReturnValue", "WeakerAccess"}) public synchronized int appendRootLevelRecord(Record newRecord) { int addedAt = -1; - org.apache.poi.hslf.record.Record[] r = new org.apache.poi.hslf.record.Record[_records.length + 1]; + Record[] r = new Record[_records.length + 1]; boolean added = false; for (int i = (_records.length - 1); i >= 0; i--) { if (added) { @@ -770,7 +770,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { /** * Returns an array of all the records found in the slideshow */ - public org.apache.poi.hslf.record.Record[] getRecords() { + public Record[] getRecords() { return _records; } @@ -815,7 +815,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { public HSLFObjectData[] getEmbeddedObjects() { if (_objects == null) { List<HSLFObjectData> objects = new ArrayList<>(); - for (org.apache.poi.hslf.record.Record r : _records) { + for (Record r : _records) { if (r instanceof ExOleObjStg) { objects.add(new HSLFObjectData((ExOleObjStg) r)); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index 867f573fcb..3f1e48c6af 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -17,6 +17,7 @@ package org.apache.poi.hslf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.hslf.record.RecordTypes.OutlineTextRefAtom; import java.awt.Color; @@ -28,6 +29,8 @@ import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.fonts.FontGroup; import org.apache.poi.common.usermodel.fonts.FontInfo; import org.apache.poi.hslf.exceptions.HSLFException; @@ -48,6 +51,7 @@ import org.apache.poi.hslf.record.InteractiveInfo; import org.apache.poi.hslf.record.MasterTextPropAtom; import org.apache.poi.hslf.record.OutlineTextRefAtom; import org.apache.poi.hslf.record.PPDrawing; +import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.RecordContainer; import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.record.RoundTripHFPlaceholder12; @@ -70,8 +74,6 @@ import org.apache.poi.sl.usermodel.TabStop; import org.apache.poi.sl.usermodel.TabStop.TabStopType; import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; import org.apache.poi.util.Units; @@ -82,7 +84,7 @@ import org.apache.poi.util.Units; */ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFTextParagraph,HSLFTextRun> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFTextParagraph.class); + private static final Logger LOG = LogManager.getLogger(HSLFTextParagraph.class); /** * How to align the text @@ -258,7 +260,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText /** * Returns the type of the text, from the TextHeaderAtom. * Possible values can be seen from TextHeaderAtom - * @see org.apache.poi.hslf.record.TextHeaderAtom + * @see TextHeaderAtom */ public int getRunType() { return (_headerAtom != null) ? _headerAtom.getTextType() : -1; @@ -286,7 +288,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText _ruler = getTextRuler(); if (_ruler == null) { _ruler = TextRulerAtom.getParagraphInstance(); - org.apache.poi.hslf.record.Record childAfter = _byteAtom; + Record childAfter = _byteAtom; if (childAfter == null) { childAfter = _charAtom; } @@ -304,37 +306,37 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText * * @return text run records */ - public org.apache.poi.hslf.record.Record[] getRecords() { - org.apache.poi.hslf.record.Record[] r = _headerAtom.getParentRecord().getChildRecords(); + public Record[] getRecords() { + Record[] r = _headerAtom.getParentRecord().getChildRecords(); return getRecords(r, new int[] { 0 }, _headerAtom); } - private static org.apache.poi.hslf.record.Record[] getRecords(org.apache.poi.hslf.record.Record[] records, int[] startIdx, TextHeaderAtom headerAtom) { + private static Record[] getRecords(Record[] records, int[] startIdx, TextHeaderAtom headerAtom) { if (records == null) { throw new NullPointerException("records need to be set."); } for (; startIdx[0] < records.length; startIdx[0]++) { - org.apache.poi.hslf.record.Record r = records[startIdx[0]]; + Record r = records[startIdx[0]]; if (r instanceof TextHeaderAtom && (headerAtom == null || r == headerAtom)) { break; } } if (startIdx[0] >= records.length) { - LOG.log(POILogger.INFO, "header atom wasn't found - container might contain only an OutlineTextRefAtom"); - return new org.apache.poi.hslf.record.Record[0]; + LOG.atInfo().log("header atom wasn't found - container might contain only an OutlineTextRefAtom"); + return new Record[0]; } int length; for (length = 1; startIdx[0] + length < records.length; length++) { - org.apache.poi.hslf.record.Record r = records[startIdx[0]+length]; + Record r = records[startIdx[0]+length]; if (r instanceof TextHeaderAtom || r instanceof SlidePersistAtom) { break; } } - org.apache.poi.hslf.record.Record[] result = Arrays.copyOfRange(records, startIdx[0], startIdx[0]+length, org.apache.poi.hslf.record.Record[].class); + Record[] result = Arrays.copyOfRange(records, startIdx[0], startIdx[0]+length, Record[].class); startIdx[0] += length; return result; @@ -884,7 +886,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText } else { master = sheet.getMasterSheet(); if (master == null) { - LOG.log(POILogger.WARN, "MasterSheet is not available"); + LOG.atWarn().log("MasterSheet is not available"); return null; } } @@ -970,7 +972,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText private static StyleTextPropAtom findStyleAtomPresent(TextHeaderAtom header, int textLen) { boolean afterHeader = false; StyleTextPropAtom style = null; - for (org.apache.poi.hslf.record.Record record : header.getParentRecord().getChildRecords()) { + for (Record record : header.getParentRecord().getChildRecords()) { long rt = record.getRecordType(); if (afterHeader && rt == RecordTypes.TextHeaderAtom.typeID) { // already on the next header, quit searching @@ -984,7 +986,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText } if (style == null) { - LOG.log(POILogger.INFO, "styles atom doesn't exist. Creating dummy record for later saving."); + LOG.atInfo().log("styles atom doesn't exist. Creating dummy record for later saving."); style = new StyleTextPropAtom((textLen < 0) ? 1 : textLen); } else { if (textLen >= 0) { @@ -1027,7 +1029,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText StyleTextPropAtom styleAtom = findStyleAtomPresent(headerAtom, rawText.length()); // Store in the appropriate record - org.apache.poi.hslf.record.Record oldRecord = null, newRecord; + Record oldRecord = null, newRecord; if (isUnicode) { if (byteAtom != null || charAtom == null) { oldRecord = byteAtom; @@ -1048,10 +1050,10 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText assert (newRecord != null); RecordContainer _txtbox = headerAtom.getParentRecord(); - org.apache.poi.hslf.record.Record[] cr = _txtbox.getChildRecords(); + Record[] cr = _txtbox.getChildRecords(); int /* headerIdx = -1, */ textIdx = -1, styleIdx = -1; for (int i = 0; i < cr.length; i++) { - org.apache.poi.hslf.record.Record r = cr[i]; + Record r = cr[i]; if (r == headerAtom) { // headerIdx = i; } else if (r == oldRecord || r == newRecord) { @@ -1137,7 +1139,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText // If TextSpecInfoAtom is present, we must update the text size in it, // otherwise the ppt will be corrupted - for (org.apache.poi.hslf.record.Record r : paragraphs.get(0).getRecords()) { + for (Record r : paragraphs.get(0).getRecords()) { if (r instanceof TextSpecInfoAtom) { ((TextSpecInfoAtom) r).setParentSize(rawText.length() + 1); break; @@ -1149,7 +1151,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom; RecordContainer _txtbox = headerAtom.getParentRecord(); // remove existing hyperlink records - for (org.apache.poi.hslf.record.Record r : _txtbox.getChildRecords()) { + for (Record r : _txtbox.getChildRecords()) { if (r instanceof InteractiveInfo || r instanceof TxInteractiveInfoAtom) { _txtbox.removeChild(r); } @@ -1395,7 +1397,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText } } if (rv == null || rv.isEmpty()) { - LOG.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx); + LOG.atWarn().log("text run not found for OutlineTextRefAtom.TextIndex={}", box(idx)); } } else { if (sheet != null) { @@ -1441,7 +1443,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText * * @param records the records to build from */ - protected static List<List<HSLFTextParagraph>> findTextParagraphs(org.apache.poi.hslf.record.Record[] records) { + protected static List<List<HSLFTextParagraph>> findTextParagraphs(Record[] records) { List<List<HSLFTextParagraph>> paragraphCollection = new ArrayList<>(); int[] recordIdx = { 0 }; @@ -1453,7 +1455,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText TextRulerAtom ruler = null; MasterTextPropAtom indents = null; - for (org.apache.poi.hslf.record.Record r : getRecords(records, recordIdx, null)) { + for (Record r : getRecords(records, recordIdx, null)) { long rt = r.getRecordType(); if (RecordTypes.TextHeaderAtom.typeID == rt) { header = (TextHeaderAtom) r; @@ -1481,7 +1483,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText if (tbytes == null && tchars == null) { tbytes = new TextBytesAtom(); // don't add record yet - set it in storeText - LOG.log(POILogger.INFO, "bytes nor chars atom doesn't exist. Creating dummy record for later saving."); + LOG.atInfo().log("bytes nor chars atom doesn't exist. Creating dummy record for later saving."); } String rawText = (tchars != null) ? tchars.getText() : tbytes.getText(); @@ -1510,7 +1512,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText } if (paragraphCollection.isEmpty()) { - LOG.log(POILogger.DEBUG, "No text records found."); + LOG.atDebug().log("No text records found."); } return paragraphCollection; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java index c17f60c1e0..2ffd690264 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java @@ -20,6 +20,8 @@ package org.apache.poi.hslf.usermodel; import java.awt.Color; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.fonts.FontGroup; import org.apache.poi.common.usermodel.fonts.FontInfo; import org.apache.poi.hslf.exceptions.HSLFException; @@ -36,8 +38,6 @@ import org.apache.poi.sl.usermodel.Placeholder; import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextShape; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** @@ -46,7 +46,7 @@ import org.apache.poi.util.POILogger; */ @SuppressWarnings({"WeakerAccess", "Duplicates", "unused"}) public final class HSLFTextRun implements TextRun { - private static final POILogger LOG = POILogFactory.getLogger(HSLFTextRun.class); + private static final Logger LOG = LogManager.getLogger(HSLFTextRun.class); /** The TextRun we belong to */ private HSLFTextParagraph parentParagraph; @@ -147,13 +147,13 @@ public final class HSLFTextRun implements TextRun { final int txtype = parentParagraph.getRunType(); final HSLFSheet sheet = parentParagraph.getSheet(); if (sheet == null) { - LOG.log(POILogger.ERROR, "Sheet is not available"); + LOG.atError().log("Sheet is not available"); return null; } final HSLFMasterSheet master = sheet.getMasterSheet(); if (master == null) { - LOG.log(POILogger.WARN, "MasterSheet is not available"); + LOG.atWarn().log("MasterSheet is not available"); return null; } @@ -414,7 +414,7 @@ public final class HSLFTextRun implements TextRun { * Sets color of the text, as a int bgr. * (PowerPoint stores as BlueGreenRed, not the more * usual RedGreenBlue) - * @see java.awt.Color + * @see Color */ public void setFontColor(int bgr) { setCharTextPropVal("font.color", bgr); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java index a7fd67bb0b..9a60a2e8ae 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java @@ -29,6 +29,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.AbstractEscherOptRecord; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherPropertyTypes; @@ -54,8 +56,6 @@ import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.sl.usermodel.VerticalAlignment; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; /** @@ -63,7 +63,7 @@ import org.apache.poi.util.Units; */ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape<HSLFShape,HSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(HSLFTextShape.class); + private static final Logger LOG = LogManager.getLogger(HSLFTextShape.class); /** * How to anchor the text @@ -324,7 +324,7 @@ implements TextShape<HSLFShape,HSLFTextParagraph> { public Rectangle2D resizeToFitText(Graphics2D graphics) { Rectangle2D anchor = getAnchor(); if(anchor.getWidth() == 0.) { - LOG.log(POILogger.WARN, "Width of shape wasn't set. Defaulting to 200px"); + LOG.atWarn().log("Width of shape wasn't set. Defaulting to 200px"); anchor.setRect(anchor.getX(), anchor.getY(), 200., anchor.getHeight()); setAnchor(anchor); } @@ -341,7 +341,7 @@ implements TextShape<HSLFShape,HSLFTextParagraph> { /** * Returns the type of the text, from the TextHeaderAtom. * Possible values can be seen from TextHeaderAtom - * @see org.apache.poi.hslf.record.TextHeaderAtom + * @see TextHeaderAtom */ public int getRunType() { getEscherTextboxWrapper(); @@ -356,7 +356,7 @@ implements TextShape<HSLFShape,HSLFTextParagraph> { * Changes the type of the text. Values should be taken * from TextHeaderAtom. No checking is done to ensure you * set this to a valid value! - * @see org.apache.poi.hslf.record.TextHeaderAtom + * @see TextHeaderAtom */ public void setRunType(int type) { getEscherTextboxWrapper(); @@ -641,7 +641,7 @@ implements TextShape<HSLFShape,HSLFTextParagraph> { } if (_paragraphs.isEmpty()) { - LOG.log(POILogger.WARN, "TextRecord didn't contained any text lines"); + LOG.atWarn().log("TextRecord didn't contained any text lines"); } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index 469bd9b6d1..6e36712276 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.POIReadOnlyDocument; import org.apache.poi.hmef.attribute.MAPIRtfAttribute; import org.apache.poi.hsmf.datatypes.AttachmentChunks; @@ -51,8 +53,8 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.CodePageUtil; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * Reads an Outlook MSG File in and provides hooks into its data structure. @@ -79,9 +81,9 @@ public class MAPIMessage extends POIReadOnlyDocument { } /** For logging problems we spot with the file */ - private static final POILogger LOG = POILogFactory.getLogger(MAPIMessage.class); + private static final Logger LOG = LogManager.getLogger(MAPIMessage.class); - private Chunks mainChunks; + private Chunks mainChunks; private NameIdChunks nameIdChunks; private RecipientChunks[] recipientChunks; private AttachmentChunks[] attachmentChunks; @@ -221,8 +223,7 @@ public class MAPIMessage extends POIReadOnlyDocument { byte[] htmlBodyBinary = htmlBodyBinaryChunk.getValue(); return new String(htmlBodyBinary, encoding); } catch (UnsupportedEncodingException e) { - LOG.log(POILogger.WARN, "HTML body binary: Invalid codepage ID ", codepage, " set for the message via ", - MAPIProperty.INTERNET_CPID, ", ignoring"); + LOG.atWarn().log("HTML body binary: Invalid codepage ID {} set for the message via {}, ignoring", box(codepage), MAPIProperty.INTERNET_CPID); } } return htmlBodyBinaryChunk.getAs7bitString(); @@ -418,8 +419,7 @@ public class MAPIMessage extends POIReadOnlyDocument { String encoding = CodePageUtil.codepageToEncoding(codepage, true); generalcodepage = encoding; } catch (UnsupportedEncodingException e) { - LOG.log(POILogger.WARN, "Invalid codepage ID ", codepage, " set for the message via ", - MAPIProperty.MESSAGE_CODEPAGE, ", ignoring"); + LOG.atWarn().log("Invalid codepage ID {} set for the message via {}, ignoring", box(codepage), MAPIProperty.MESSAGE_CODEPAGE); } } // @@ -436,8 +436,7 @@ public class MAPIMessage extends POIReadOnlyDocument { generalcodepage = encoding; } } catch (UnsupportedEncodingException e) { - LOG.log(POILogger.WARN, "Invalid codepage ID ", codepage, "from locale ID", lcid, " set for the message via ", - MAPIProperty.MESSAGE_LOCALE_ID, ", ignoring"); + LOG.atWarn().log("Invalid codepage ID {}from locale ID{} set for the message via {}, ignoring", box(codepage),box(lcid), MAPIProperty.MESSAGE_LOCALE_ID); } } } @@ -476,8 +475,7 @@ public class MAPIMessage extends POIReadOnlyDocument { bodycodepage = encoding; } } catch (UnsupportedEncodingException e) { - LOG.log(POILogger.WARN, "Invalid codepage ID ", codepage, " set for the message via ", - MAPIProperty.INTERNET_CPID, ", ignoring"); + LOG.atWarn().log("Invalid codepage ID {} set for the message via {}, ignoring", box(codepage), MAPIProperty.INTERNET_CPID); } } // @@ -617,8 +615,7 @@ public class MAPIMessage extends POIReadOnlyDocument { } else if (mc.equalsIgnoreCase("IPM.Post")) { return MESSAGE_CLASS.POST; } else { - LOG.log(POILogger.WARN, "I don't recognize message class '", mc, "'. ", - "Please open an issue on POI's bugzilla"); + LOG.atWarn().log("I don't recognize message class '{}'. Please open an issue on POI's bugzilla", mc); return MESSAGE_CLASS.UNKNOWN; } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index d683ba8567..83e5159813 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -30,16 +30,16 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hsmf.MAPIMessage; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Collection of convenience chunks for standard parts of the MSG file * attachment. */ public class AttachmentChunks implements ChunkGroup { - private static final POILogger LOG = POILogFactory.getLogger(AttachmentChunks.class); + private static final Logger LOG = LogManager.getLogger(AttachmentChunks.class); public static final String PREFIX = "__attach_version1.0_#"; private ByteChunk attachData; @@ -187,7 +187,7 @@ public class AttachmentChunks implements ChunkGroup { } else if (chunk instanceof DirectoryChunk) { attachmentDirectory = (DirectoryChunk) chunk; } else { - LOG.log(POILogger.ERROR, "Unexpected data chunk of type ", chunk.getEntryName()); + LOG.atError().log("Unexpected data chunk of type {}", chunk.getEntryName()); } } else if (chunkId == ATTACH_EXTENSION.id) { attachExtension = (StringChunk) chunk; @@ -202,7 +202,7 @@ public class AttachmentChunks implements ChunkGroup { } else if (chunkId == ATTACH_CONTENT_ID.id) { attachContentId = (StringChunk) chunk; } else { - LOG.log(POILogger.WARN, "Currently unsupported attachment chunk property will be ignored. ", chunk.getEntryName()); + LOG.atWarn().log("Currently unsupported attachment chunk property will be ignored. {}", chunk.getEntryName()); } // And add to the main list diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java index 82b3c00646..041ab37556 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -23,8 +23,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Collection of convenience chunks for standard parts of the MSG file. @@ -37,7 +37,7 @@ import org.apache.poi.util.POILogger; * TODO Deprecate the public Chunks in favour of Property Lookups */ public final class Chunks implements ChunkGroupWithProperties { - private static final POILogger LOG = POILogFactory.getLogger(Chunks.class); + private static final Logger LOG = LogManager.getLogger(Chunks.class); /** * Holds all the chunks that were found, indexed by their MAPIProperty. @@ -262,8 +262,7 @@ public final class Chunks implements ChunkGroupWithProperties { if (messageProperties != null) { messageProperties.matchVariableSizedPropertiesToChunks(); } else { - LOG.log(POILogger.WARN, - "Message didn't contain a root list of properties!"); + LOG.atWarn().log("Message didn't contain a root list of properties!"); } } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java index 20f856d4cc..f1ef43c766 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java @@ -24,11 +24,11 @@ import java.util.Calendar; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hsmf.datatypes.Types.MAPIType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * A Chunk that holds the details given back by the server at submission time. @@ -36,7 +36,7 @@ import org.apache.poi.util.POILogger; * used if you want to cancel a message or similar */ public class MessageSubmissionChunk extends Chunk { - private static final POILogger LOG = POILogFactory.getLogger(MessageSubmissionChunk.class); + private static final Logger LOG = LogManager.getLogger(MessageSubmissionChunk.class); private String rawId; private Calendar date; @@ -103,8 +103,7 @@ public class MessageSubmissionChunk extends Chunk { date.set(Calendar.SECOND, Integer.parseInt(m.group(6))); date.clear(Calendar.MILLISECOND); } else { - LOG.log(POILogger.WARN, - "Warning - unable to make sense of date ", dateS); + LOG.atWarn().log("Warning - unable to make sense of date {}", dateS); } } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java index 8800437bbd..6cf92111a6 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java @@ -30,6 +30,8 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hsmf.datatypes.PropertyValue.BooleanPropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.CurrencyPropertyValue; import org.apache.poi.hsmf.datatypes.PropertyValue.DoublePropertyValue; @@ -44,8 +46,8 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian.BufferUnderrunException; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * <p> @@ -68,7 +70,7 @@ public abstract class PropertiesChunk extends Chunk { public static final int PROPERTIES_FLAG_WRITEABLE = 4; /** For logging problems we spot with the file */ - private static final POILogger LOG = POILogFactory.getLogger(PropertiesChunk.class); + private static final Logger LOG = LogManager.getLogger(PropertiesChunk.class); /** * Holds properties, indexed by type. If a property is multi-valued, or @@ -176,7 +178,7 @@ public abstract class PropertiesChunk extends Chunk { if (chunk != null) { cVal.setValue(chunk); } else { - LOG.log(POILogger.WARN, "No chunk found matching Property " + cVal); + LOG.atWarn().log("No chunk found matching Property {}", cVal); } } } @@ -200,9 +202,7 @@ public abstract class PropertiesChunk extends Chunk { prop = MAPIProperty.createCustom(id, type, "Unknown " + id); } if (type == null) { - LOG.log(POILogger.WARN, "Invalid type found, expected ", - prop.usualType, " but got ", typeID, - " for property ", prop); + LOG.atWarn().log("Invalid type found, expected {} but got {} for property {}", prop.usualType, box(typeID),prop); going = false; break; } @@ -220,12 +220,10 @@ public abstract class PropertiesChunk extends Chunk { // We don't know what this property normally is, but it // has come // through with a valid type, so use that - LOG.log(POILogger.INFO, "Property definition for ", prop, - " is missing a type definition, found a value with type ", type); + LOG.atInfo().log("Property definition for {} is missing a type definition, found a value with type {}", prop, type); } else { // Oh dear, something has gone wrong... - LOG.log(POILogger.WARN, "Type mismatch, expected ", - prop.usualType, " but got ", type, " for property ", prop); + LOG.atWarn().log("Type mismatch, expected {} but got {} for property {}", prop.usualType, type, prop); going = false; break; } @@ -285,8 +283,7 @@ public abstract class PropertiesChunk extends Chunk { } if (properties.get(prop) != null) { - LOG.log(POILogger.WARN, - "Duplicate values found for " + prop); + LOG.atWarn().log("Duplicate values found for {}", prop); } properties.put(prop, propVal); } catch (BufferUnderrunException e) { @@ -310,7 +307,7 @@ public abstract class PropertiesChunk extends Chunk { baos.close(); // write the header data with the properties declaration - directory.createDocument(org.apache.poi.hsmf.datatypes.PropertiesChunk.NAME, + directory.createDocument(PropertiesChunk.NAME, new ByteArrayInputStream(baos.toByteArray())); // write the property values @@ -319,7 +316,7 @@ public abstract class PropertiesChunk extends Chunk { /** * Write the nodes for variable-length data. Those properties are returned by - * {@link #writeProperties(java.io.OutputStream)}. + * {@link #writeProperties(OutputStream)}. * * @param directory * The directory. diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java index efcd051eb9..8b37806fdc 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java @@ -24,8 +24,8 @@ import java.util.Comparator; import java.util.List; import java.util.Map; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Collection of convenience chunks for the Recip(ient) part of an outlook file. @@ -33,7 +33,7 @@ import org.apache.poi.util.POILogger; * If a message has multiple recipients, there will be several of these. */ public final class RecipientChunks implements ChunkGroupWithProperties { - private static final POILogger LOG = POILogFactory.getLogger(RecipientChunks.class); + private static final Logger LOG = LogManager.getLogger(RecipientChunks.class); public static final String PREFIX = "__recip_version1.0_#"; @@ -88,7 +88,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties { try { recipientNumber = Integer.parseInt(number, 16); } catch (NumberFormatException e) { - LOG.log(POILogger.ERROR, "Invalid recipient number in name ", name); + LOG.atError().log("Invalid recipient number in name {}", name); } } } @@ -238,7 +238,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties { if (recipientProperties != null) { recipientProperties.matchVariableSizedPropertiesToChunks(); } else { - LOG.log(POILogger.WARN, "Recipeints Chunk didn't contain a list of properties!"); + LOG.atWarn().log("Recipients Chunk didn't contain a list of properties!"); } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java index 5db7ade98a..086a653086 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hsmf.datatypes.AttachmentChunks; import org.apache.poi.hsmf.datatypes.ByteChunk; import org.apache.poi.hsmf.datatypes.ByteChunkDeferred; @@ -46,8 +48,6 @@ import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.DocumentNode; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Processes a POIFS of a .msg file into groups of Chunks, such as @@ -55,7 +55,7 @@ import org.apache.poi.util.POILogger; * data and so on. */ public final class POIFSChunkParser { - private static final POILogger LOG = POILogFactory.getLogger(POIFSChunkParser.class); + private static final Logger LOG = LogManager.getLogger(POIFSChunkParser.class); private POIFSChunkParser() {} @@ -149,7 +149,7 @@ public final class POIFSChunkParser { try (DocumentInputStream inp = new DocumentInputStream((DocumentNode) entry)) { chunk.readValue(inp); } catch (IOException e) { - LOG.log(POILogger.ERROR, "Error reading from part ", entry.getName(), e); + LOG.atError().withThrowable(e).log("Error reading from part {}", entry.getName()); } } @@ -234,7 +234,7 @@ public final class POIFSChunkParser { return new StringChunk(namePrefix, chunkId, type); } // Type of an unsupported type! Skipping... - LOG.log(POILogger.WARN, "UNSUPPORTED PROP TYPE ", entryName); + LOG.atWarn().log("UNSUPPORTED PROP TYPE {}", entryName); return null; } } @@ -249,7 +249,7 @@ public final class POIFSChunkParser { try { multiValueIdx = Long.parseLong(mvidxstr) & 0xFFFFFFFFL; } catch (NumberFormatException ignore) { - LOG.log(POILogger.WARN, "Can't read multi value idx from entry ", entry.getName()); + LOG.atWarn().log("Can't read multi value idx from entry {}", entry.getName()); } } @@ -270,7 +270,7 @@ public final class POIFSChunkParser { chunk = new StringChunk(namePrefix, chunkId, type); } else { // Type of an unsupported multivalued type! Skipping... - LOG.log(POILogger.WARN, "Unsupported multivalued prop type for entry ", entry.getName()); + LOG.atWarn().log("Unsupported multivalued prop type for entry {}", entry.getName()); return null; } mc.addChunk((int) multiValueIdx, chunk); diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java index 08b5c4ec22..50cf5427b2 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java @@ -24,6 +24,8 @@ import javax.xml.transform.Transformer; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; @@ -41,8 +43,6 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -60,7 +60,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter private static final float DPI = 72; - private static final POILogger LOG = POILogFactory.getLogger( ExcelToFoConverter.class ); + private static final Logger LOG = LogManager.getLogger(ExcelToFoConverter.class); private static final float PAPER_A4_HEIGHT_INCHES = 29.4f / CM_PER_INCH; @@ -232,10 +232,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter value = ErrorEval.getText( cell.getErrorCellValue() ); break; default: - LOG.log( - POILogger.WARN, - "Unexpected cell cachedFormulaResultType (" - + cell.getCachedFormulaResultType() + ")" ); + LOG.atWarn().log("Unexpected cell cachedFormulaResultType ({})", cell.getCachedFormulaResultType()); value = AbstractExcelUtils.EMPTY; break; } @@ -253,8 +250,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter value = ErrorEval.getText( cell.getErrorCellValue() ); break; default: - LOG.log( POILogger.WARN, - "Unexpected cell type (" + cell.getCellType() + ")" ); + LOG.atWarn().log("Unexpected cell type ({})", cell.getCellType()); return true; } diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java index ea6bf7665d..0110c71ec9 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -30,6 +30,8 @@ import javax.xml.transform.Transformer; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; @@ -44,8 +46,6 @@ import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -58,7 +58,7 @@ import org.w3c.dom.Text; */ @Beta public class ExcelToHtmlConverter extends AbstractExcelConverter { - private static final POILogger LOG = POILogFactory.getLogger( ExcelToHtmlConverter.class ); + private static final Logger LOG = LogManager.getLogger(ExcelToHtmlConverter.class); /** * Java main() interface to interact with {@link ExcelToHtmlConverter} @@ -322,10 +322,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { value = ErrorEval.getText( cell.getErrorCellValue() ); break; default: - LOG.log( - POILogger.WARN, - "Unexpected cell cachedFormulaResultType (" - + cell.getCachedFormulaResultType() + ")" ); + LOG.atWarn().log("Unexpected cell cachedFormulaResultType ({})", cell.getCachedFormulaResultType()); value = AbstractExcelUtils.EMPTY; break; } @@ -343,8 +340,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter { value = ErrorEval.getText( cell.getErrorCellValue() ); break; default: - LOG.log( POILogger.WARN, - "Unexpected cell type (" + cell.getCellType() + ")" ); + LOG.atWarn().log("Unexpected cell type ({})", cell.getCellType()); return true; } diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java index 7af8322f01..91597803e1 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java @@ -36,6 +36,8 @@ import java.util.function.Supplier; import javax.imageio.ImageIO; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hwmf.usermodel.HwmfPicture; import org.apache.poi.util.GenericRecordJsonWriter; @@ -43,8 +45,6 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInputStream; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.RecordFormatException; /** @@ -52,7 +52,7 @@ import org.apache.poi.util.RecordFormatException; */ public class HwmfBitmapDib implements GenericRecord { - private static final POILogger LOG = POILogFactory.getLogger(HwmfBitmapDib.class); + private static final Logger LOG = LogManager.getLogger(HwmfBitmapDib.class); private static final int BMP_HEADER_SIZE = 14; private static final int MAX_RECORD_LENGTH = HwmfPicture.MAX_RECORD_LENGTH; @@ -479,11 +479,11 @@ public class HwmfBitmapDib implements GenericRecord { try { bi = ImageIO.read(getBMPStream()); } catch (IOException|RuntimeException e) { - LOG.log(POILogger.ERROR, "invalid bitmap data - returning placeholder image"); + LOG.atError().log("invalid bitmap data - returning placeholder image"); return getPlaceholder(); } - if (foreground != null && background != null && headerBitCount == HwmfBitmapDib.BitCount.BI_BITCOUNT_1) { + if (foreground != null && background != null && headerBitCount == BitCount.BI_BITCOUNT_1) { IndexColorModel cmOld = (IndexColorModel)bi.getColorModel(); int fg = foreground.getRGB(); int bg = background.getRGB() & (hasAlpha ? 0xFFFFFF : 0xFFFFFFFF); diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java index c806befd00..6f72d28650 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java @@ -31,6 +31,8 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hwmf.draw.HwmfDrawProperties; import org.apache.poi.hwmf.draw.HwmfGraphics; @@ -44,11 +46,9 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; public class HwmfText { - private static final POILogger LOG = POILogFactory.getLogger(HwmfText.class); + private static final Logger LOG = LogManager.getLogger(HwmfText.class); private static final int MAX_RECORD_LENGTH = 1_000_000; /** @@ -430,13 +430,13 @@ public class HwmfText { size += rawTextBytes.length; if (size >= remainingRecordSize) { - LOG.log(POILogger.INFO, "META_EXTTEXTOUT doesn't contain character tracking info"); + LOG.atInfo().log("META_EXTTEXTOUT doesn't contain character tracking info"); return size; } int dxLen = Math.min(stringLength, (remainingRecordSize-size)/LittleEndianConsts.SHORT_SIZE); if (dxLen < stringLength) { - LOG.log(POILogger.WARN, "META_EXTTEXTOUT tracking info doesn't cover all characters"); + LOG.atWarn().log("META_EXTTEXTOUT tracking info doesn't cover all characters"); } for (int i=0; i<dxLen; i++) { diff --git a/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfPicture.java b/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfPicture.java index 76096de417..0fb9637f6a 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfPicture.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfPicture.java @@ -34,6 +34,8 @@ import java.util.Objects; import java.util.Spliterator; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.hwmf.draw.HwmfDrawProperties; import org.apache.poi.hwmf.draw.HwmfGraphics; @@ -48,8 +50,6 @@ import org.apache.poi.util.Dimension2DDouble; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.RecordFormatException; import org.apache.poi.util.Units; @@ -57,7 +57,7 @@ public class HwmfPicture implements Iterable<HwmfRecord>, GenericRecord { /** Max. record length - processing longer records will throw an exception */ public static final int MAX_RECORD_LENGTH = 50_000_000; - private static final POILogger LOG = POILogFactory.getLogger(HwmfPicture.class); + private static final Logger LOG = LogManager.getLogger(HwmfPicture.class); final List<HwmfRecord> records = new ArrayList<>(); final HwmfPlaceableHeader placeableHeader; @@ -85,7 +85,7 @@ public class HwmfPicture implements Iterable<HwmfRecord>, GenericRecord { recordSize = (int)recordSizeLong; recordFunction = leis.readShort(); } catch (Exception e) { - LOG.log(POILogger.ERROR, "unexpected eof - wmf file was truncated"); + LOG.atError().log("unexpected eof - wmf file was truncated"); break; } // 4 bytes (recordSize) + 2 bytes (recordFunction) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java index dd44d45d70..a5a3d441cb 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.hwpf.model.ComplexFileTable; import org.apache.poi.hwpf.model.FontTable; @@ -41,8 +43,6 @@ import org.apache.poi.hwpf.util.DoubleByteUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.NotImplemented; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -51,7 +51,7 @@ import org.apache.poi.util.StringUtil; */ public class HWPFOldDocument extends HWPFDocumentCore { - private static final POILogger LOG = POILogFactory.getLogger( HWPFOldDocument.class ); + private static final Logger LOG = LogManager.getLogger(HWPFOldDocument.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 10_000_000; @@ -114,7 +114,7 @@ public class HWPFOldDocument extends HWPFDocumentCore { //if there was a problem with the guessed charset and the length of the //textpiece, back off to win1252. This is effectively what we used to do. tp = buildTextPiece(StringUtil.WIN_1252); - LOG.log(POILogger.WARN, "Error with "+guessedCharset +". Backing off to Windows-1252"); + LOG.atWarn().log("Error with {}. Backing off to Windows-1252", guessedCharset); } tpt.add(tp); @@ -205,7 +205,7 @@ public class HWPFOldDocument extends HWPFDocumentCore { return wmfCharset.getCharset(); } } - LOG.log(POILogger.WARN, "Couldn't find a defined charset; backing off to cp1252"); + LOG.atWarn().log("Couldn't find a defined charset; backing off to cp1252"); //if all else fails return DEFAULT_CHARSET; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java index 741ee21c47..1ff262d456 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java @@ -27,6 +27,8 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; @@ -50,11 +52,11 @@ import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.w3c.dom.Document; import org.w3c.dom.Element; +import static org.apache.logging.log4j.util.Unbox.box; + @Beta public abstract class AbstractWordConverter { private static class DeadFieldBoundaries { @@ -115,7 +117,7 @@ public abstract class AbstractWordConverter { private static final int FIELD_HYPERLINK = 88; - private static final POILogger LOG = POILogFactory.getLogger(AbstractWordConverter.class); + private static final Logger LOG = LogManager.getLogger(AbstractWordConverter.class); private static final Pattern PATTERN_HYPERLINK_EXTERNAL = Pattern .compile("^[ \\t\\r\\n]*HYPERLINK \"(.*)\".*$"); @@ -399,10 +401,8 @@ public abstract class AbstractWordConverter { if (previous != range.getStartOffset()) { if (previous > range.getEndOffset()) { - LOG.log(POILogger.WARN, "Latest structure in ", range, - " ended at #", previous, " after range boundaries [", - range.getStartOffset(), "; ", range.getEndOffset(), - ")"); + LOG.atWarn().log("Latest structure in {} ended at #{} after range boundaries [{}; {})", + range, box(previous),box(range.getStartOffset()),box(range.getEndOffset())); return true; } @@ -595,7 +595,7 @@ public abstract class AbstractWordConverter { debug.append(range.getCharacterRun(i)); debug.append("\n"); } - LOG.log(POILogger.WARN, debug); + LOG.atWarn().log(debug); Range deadFieldValueSubrage = new Range(range.getCharacterRun( separatorMark).getStartOffset() + 1, range.getCharacterRun( @@ -621,7 +621,7 @@ public abstract class AbstractWordConverter { processDocumentInformation(summaryInformation); } } catch (Exception exc) { - LOG.log(POILogger.WARN, "Unable to process document summary information: ", exc, exc); + LOG.atWarn().withThrowable(exc).log("Unable to process document summary information"); } final Range docRange = wordDocument.getRange(); @@ -656,8 +656,7 @@ public abstract class AbstractWordConverter { OfficeDrawing officeDrawing = doc.getOfficeDrawingsMain() .getOfficeDrawingAt(characterRun.getStartOffset()); if (officeDrawing == null) { - LOG.log(POILogger.WARN, "Characters #", characterRun, - " references missing drawn object"); + LOG.atWarn().log("Characters #{} references missing drawn object", characterRun); return; } @@ -715,8 +714,7 @@ public abstract class AbstractWordConverter { } case FIELD_EMBEDDED_OBJECT: { if (!field.hasSeparator()) { - LOG.log(POILogger.WARN, parentRange, " contains ", field, - " with 'Embedded Object' but without separator mark"); + LOG.atWarn().log("{} contains {} with 'Embedded Object' but without separator mark", parentRange, field); return; } @@ -790,7 +788,7 @@ public abstract class AbstractWordConverter { } } - LOG.log(POILogger.WARN, parentRange, " contains ", field, " with unsupported type or format"); + LOG.atWarn().log("{} contains {} with unsupported type or format", parentRange, field); processCharacters(wordDocument, currentTableLevel, field.secondSubrange(parentRange), currentBlock); } @@ -881,14 +879,14 @@ public abstract class AbstractWordConverter { Element block) { Entry entry = doc.getObjectsPool().getObjectById("_" + characterRun.getPicOffset()); if (entry == null) { - LOG.log(POILogger.WARN, "Referenced OLE2 object '", characterRun.getPicOffset(), "' not found in ObjectPool"); + LOG.atWarn().log("Referenced OLE2 object '{}' not found in ObjectPool", box(characterRun.getPicOffset())); return false; } try { return processOle2(doc, block, entry); } catch (Exception exc) { - LOG.log(POILogger.WARN, "Unable to convert internal OLE2 object '", characterRun.getPicOffset(), "': ", exc, exc); + LOG.atWarn().withThrowable(exc).log("Unable to convert internal OLE2 object '{}'", box(characterRun.getPicOffset())); return false; } } @@ -943,7 +941,7 @@ public abstract class AbstractWordConverter { processParagraph(wordDocument, flow, currentTableLevel, paragraph, label); processed = true; } catch (Exception exc) { - LOG.log(POILogger.WARN, "Can't process paragraph as list entry, will be processed without list information", exc); + LOG.atWarn().withThrowable(exc).log("Can't process paragraph as list entry, will be processed without list information"); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index ab89c92e49..1f633c5767 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -26,6 +26,8 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.HWPFOldDocument; @@ -38,20 +40,20 @@ import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import static org.apache.logging.log4j.util.Unbox.box; + @Beta public class AbstractWordUtils { static final String EMPTY = ""; - private static final POILogger LOG = POILogFactory.getLogger( AbstractWordUtils.class ); + private static final Logger LOG = LogManager.getLogger(AbstractWordUtils.class); public static final float TWIPS_PER_INCH = 1440.0f; public static final int TWIPS_PER_PT = 20; @@ -417,7 +419,7 @@ public class AbstractWordUtils case 2057: return "en-uk"; default: - LOG.log( POILogger.WARN, "Uknown or unmapped language code: ", languageCode); + LOG.atWarn().log("Unknown or unmapped language code: {}", box(languageCode)); return EMPTY; } } @@ -426,7 +428,7 @@ public class AbstractWordUtils { if ( format != 0 ) - LOG.log( POILogger.INFO, "NYI: toListItemNumberLabel(): ", format ); + LOG.atInfo().log("NYI: toListItemNumberLabel(): {}", box(format)); return String.valueOf( number ); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java index fc822954e4..d91708424c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.hwpf.converter; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH; import static org.apache.poi.hwpf.converter.AbstractWordUtils.isNotEmpty; import static org.apache.poi.hwpf.converter.AbstractWordUtils.loadDoc; @@ -33,6 +34,8 @@ import javax.xml.transform.Transformer; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; @@ -48,8 +51,6 @@ import org.apache.poi.hwpf.usermodel.Table; import org.apache.poi.hwpf.usermodel.TableCell; import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -64,7 +65,7 @@ import org.w3c.dom.Text; public class WordToFoConverter extends AbstractWordConverter { - private static final POILogger LOG = POILogFactory.getLogger( WordToFoConverter.class ); + private static final Logger LOG = LogManager.getLogger(WordToFoConverter.class); /** * Java main() interface to interact with {@link WordToFoConverter} @@ -574,11 +575,7 @@ public class WordToFoConverter extends AbstractWordConverter } else { - LOG.log( - POILogger.WARN, - "Table without body starting on offset ", - table.getStartOffset(), " -- ", - table.getEndOffset() ); + LOG.atWarn().log("Table without body starting on offset {} -- {}", box(table.getStartOffset()),box(table.getEndOffset())); } } @@ -587,8 +584,7 @@ public class WordToFoConverter extends AbstractWordConverter // making sure ID used once if ( usedIds.contains( id ) ) { - LOG.log( POILogger.WARN, - "Tried to create element with same ID '", id, "'. Skipped" ); + LOG.atWarn().log("Tried to create element with same ID '{}'. Skipped", id); return false; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java index 5a96806007..a60d504405 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.hwpf.converter; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH; import java.io.File; @@ -33,6 +34,8 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; @@ -48,8 +51,6 @@ import org.apache.poi.hwpf.usermodel.Table; import org.apache.poi.hwpf.usermodel.TableCell; import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -81,7 +82,7 @@ public class WordToHtmlConverter extends AbstractWordConverter } } - private static final POILogger LOG = POILogFactory.getLogger( WordToHtmlConverter.class ); + private static final Logger LOG = LogManager.getLogger(WordToHtmlConverter.class); private final Deque<BlockProperies> blocksProperies = new LinkedList<>(); @@ -737,9 +738,7 @@ public class WordToHtmlConverter extends AbstractWordConverter } else { - LOG.log( POILogger.WARN, "Table without body starting at [", - Integer.valueOf( table.getStartOffset() ), "; ", - Integer.valueOf( table.getEndOffset() ), ")" ); + LOG.atWarn().log("Table without body starting at [{}; {})", box(table.getStartOffset()),box(table.getEndOffset())); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java index 8ee50e5c35..cebc55b743 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java @@ -30,6 +30,8 @@ import javax.xml.transform.Transformer; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; @@ -46,8 +48,6 @@ import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -55,7 +55,7 @@ import org.w3c.dom.Element; @Beta public class WordToTextConverter extends AbstractWordConverter { - private static final POILogger LOG = POILogFactory.getLogger( WordToTextConverter.class ); + private static final Logger LOG = LogManager.getLogger(WordToTextConverter.class); public static String getText( DirectoryNode root ) throws Exception { @@ -351,10 +351,8 @@ public class WordToTextConverter extends AbstractWordConverter catch ( Exception exc ) { // no extractor in classpath - LOG.log( POILogger.WARN, "There is an OLE object entry '", - entry.getName(), - "', but there is no text extractor for this object type ", - "or text extractor factory is not available: ", "", exc ); + LOG.atWarn().withThrowable(exc).log("There is an OLE object entry '{}', but there is no text " + + "extractor for this object type or text extractor factory is not available", entry.getName()); return false; } @@ -370,9 +368,7 @@ public class WordToTextConverter extends AbstractWordConverter } catch ( Exception exc ) { - LOG.log( POILogger.ERROR, - "Unable to extract text from OLE entry '", entry.getName(), - "': ", exc, exc ); + LOG.atError().withThrowable(exc).log("Unable to extract text from OLE entry '{}'", entry.getName()); return false; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java index b5c2f7f694..1ffdbc635d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java @@ -22,15 +22,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.types.BKFAbstractType; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; @Internal public class BookmarksTables { - private static final POILogger LOG = POILogFactory.getLogger( BookmarksTables.class ); + private static final Logger LOG = LogManager.getLogger(BookmarksTables.class); private PlexOfCps descriptorsFirst = new PlexOfCps( 4 ); @@ -53,8 +55,7 @@ public class BookmarksTables GenericPropertyNode endNode = descriptorsLim.getProperty( i ); if ( startNode.getStart() == endNode.getStart() ) { - LOG.log( POILogger.DEBUG, "Removing bookmark #", - Integer.valueOf( i ), "..." ); + LOG.atDebug().log("Removing bookmark #{}...", box(i)); remove( i ); i--; continue; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index 9559f560a7..178186bd35 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -31,6 +31,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.hwpf.sprm.SprmIterator; @@ -38,8 +40,9 @@ import org.apache.poi.hwpf.sprm.SprmOperation; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static java.lang.System.currentTimeMillis; +import static org.apache.logging.log4j.util.Unbox.box; /** * This class holds all of the character formatting properties. @@ -49,9 +52,9 @@ import org.apache.poi.util.POILogger; @Internal public class CHPBinTable { - private static final POILogger LOG = POILogFactory.getLogger( CHPBinTable.class ); + private static final Logger LOG = LogManager.getLogger(CHPBinTable.class); - /** List of character properties.*/ + /** List of character properties.*/ protected List<CHPX> _textRuns = new ArrayList<>(); public CHPBinTable() @@ -77,7 +80,7 @@ public class CHPBinTable public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset, int size, CharIndexTranslator translator ) { - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); /* * Page 35: * @@ -105,20 +108,18 @@ public class CHPBinTable _textRuns.add( chpx ); } } - LOG.log( POILogger.DEBUG, "CHPX FKPs loaded in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms (", - Integer.valueOf( _textRuns.size() ), " elements)" ); + LOG.atDebug().log("CHPX FKPs loaded in {} ms ({} elements)", box(currentTimeMillis() - start),box(_textRuns.size())); if ( _textRuns.isEmpty() ) { - LOG.log( POILogger.WARN, "CHPX FKPs are empty" ); + LOG.atWarn().log("CHPX FKPs are empty"); _textRuns.add( new CHPX( 0, 0, new SprmBuffer( 0 ) ) ); } } public void rebuild( ComplexFileTable complexFileTable ) { - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); if ( complexFileTable != null ) { @@ -135,8 +136,7 @@ public class CHPBinTable if ( igrpprl < 0 || igrpprl >= sprmBuffers.length ) { - LOG.log( POILogger.WARN, textPiece - + "'s PRM references to unknown grpprl" ); + LOG.atWarn().log("{}'s PRM references to unknown grpprl", textPiece); continue; } @@ -162,20 +162,15 @@ public class CHPBinTable _textRuns.add( chpx ); } } - LOG.log( POILogger.DEBUG, - "Merged with CHPX from complex file table in ", - Long.valueOf( System.currentTimeMillis() - start ), - " ms (", Integer.valueOf( _textRuns.size() ), - " elements in total)" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("Merged with CHPX from complex file table in {} ms ({} elements in total)", box(currentTimeMillis() - start),box(_textRuns.size())); + start = currentTimeMillis(); } List<CHPX> oldChpxSortedByStartPos = new ArrayList<>(_textRuns); oldChpxSortedByStartPos.sort(PropertyNode.StartComparator); - LOG.log( POILogger.DEBUG, "CHPX sorted by start position in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("CHPX sorted by start position in {} ms", box(currentTimeMillis() - start)); + start = currentTimeMillis(); final Map<CHPX, Integer> chpxToFileOrder = new IdentityHashMap<>(); { @@ -195,9 +190,8 @@ public class CHPBinTable } }; - LOG.log( POILogger.DEBUG, "CHPX's order map created in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("CHPX's order map created in {} ms", box(currentTimeMillis() - start)); + start = currentTimeMillis(); List<Integer> textRunsBoundariesList; { @@ -213,9 +207,8 @@ public class CHPBinTable Collections.sort( textRunsBoundariesList ); } - LOG.log( POILogger.DEBUG, "Texts CHPX boundaries collected in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("Texts CHPX boundaries collected in {} ms", box(currentTimeMillis() - start)); + start = currentTimeMillis(); List<CHPX> newChpxs = new LinkedList<>(); int lastTextRunStart = 0; @@ -253,10 +246,7 @@ public class CHPBinTable if ( chpxs.size() == 0 ) { - LOG.log( POILogger.WARN, "Text piece [", - Integer.valueOf( startInclusive ), "; ", - Integer.valueOf(boundary), - ") has no CHPX. Creating new one." ); + LOG.atWarn().log("Text piece [{}; {}) has no CHPX. Creating new one.", box(startInclusive),box(boundary)); // create it manually CHPX chpx = new CHPX( startInclusive, boundary, new SprmBuffer( 0 ) ); @@ -290,10 +280,8 @@ public class CHPBinTable } this._textRuns = new ArrayList<>(newChpxs); - LOG.log( POILogger.DEBUG, "CHPX rebuilded in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms (", - Integer.valueOf( _textRuns.size() ), " elements)" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("CHPX rebuilt in {} ms ({} elements)", box(currentTimeMillis() - start),box(_textRuns.size())); + start = currentTimeMillis(); CHPX previous = null; for ( Iterator<CHPX> iterator = _textRuns.iterator(); iterator @@ -318,9 +306,7 @@ public class CHPBinTable previous = current; } - LOG.log( POILogger.DEBUG, "CHPX compacted in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms (", - Integer.valueOf( _textRuns.size() ), " elements)" ); + LOG.atDebug().log("CHPX compacted in {} ms ({} elements)", box(currentTimeMillis() - start),box(_textRuns.size())); } private static int binarySearch( List<CHPX> chpxs, int startPosition ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java index 83ca143b05..227df337c0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java @@ -24,11 +24,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; @Internal public final class FIBFieldHandler @@ -145,7 +147,7 @@ public final class FIBFieldHandler public static final int STTBLISTNAMES = 91; public static final int STTBFUSSR = 92; - private static final POILogger log = POILogFactory.getLogger(FIBFieldHandler.class); + private static final Logger LOGGER = LogManager.getLogger(FIBFieldHandler.class); private static final int FIELD_SIZE = LittleEndianConsts.INT_SIZE * 2; @@ -171,9 +173,7 @@ public final class FIBFieldHandler { if (dsOffset + dsSize > tableStream.length) { - log.log(POILogger.WARN, "Unhandled data structure points to outside the buffer. ", - "offset = ", dsOffset, ", length = ", dsSize, - ", buffer length = ", tableStream.length); + LOGGER.atWarn().log("Unhandled data structure points to outside the buffer. offset = {}, length = {}, buffer length = {}", box(dsOffset),box(dsSize),box(tableStream.length)); } else { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index 879441bf7b..fdb220540a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -24,14 +24,16 @@ import java.lang.reflect.Modifier; import java.util.HashSet; import java.util.Locale; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.types.FibBaseAbstractType; import org.apache.poi.hwpf.model.types.FibRgW97AbstractType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * <p>The File Information Block (FIB). Holds pointers @@ -50,7 +52,7 @@ public final class FileInformationBlock { //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; - private static final POILogger LOG = POILogFactory.getLogger( FileInformationBlock.class ); + private static final Logger LOG = LogManager.getLogger(FileInformationBlock.class); private final FibBase _fibBase; private final int _csw; @@ -175,7 +177,7 @@ public final class FileInformationBlock { /* The Word spec has a much smaller list of "valid" values * to what the large CommonCrawl corpus contains! */ - LOG.log(POILogger.WARN, "Invalid file format version number: ", nfib, "(", nfibHex, ")"); + LOG.atWarn().log("Invalid file format version number: {}({})", box(nfib),nfibHex); } } @@ -186,9 +188,7 @@ public final class FileInformationBlock { if ( cbRgFcLcb == expectedCbRgFcLcb ) return; - LOG.log( POILogger.WARN, "Since FIB.nFib == ", strNFib, - " value of FIB.cbRgFcLcb MUST be ", strCbRgFcLcb + ", not 0x", - Integer.toHexString( cbRgFcLcb ) ); + LOG.atWarn().log("Since FIB.nFib == {} value of FIB.cbRgFcLcb MUST be {}, not 0x{}", strNFib, strCbRgFcLcb, Integer.toHexString(cbRgFcLcb)); } private void assertCswNew() @@ -211,7 +211,7 @@ public final class FileInformationBlock { assertCswNew( "0x0112", 0x0005, "0x0005", _cswNew ); break; default: - LOG.log(POILogger.WARN, "Invalid file format version number: ", getNFib()); + LOG.atWarn().log("Invalid file format version number: {}", box(getNFib())); } } @@ -222,9 +222,7 @@ public final class FileInformationBlock { if ( cswNew == expectedCswNew ) return; - LOG.log( POILogger.WARN, "Since FIB.nFib == ", strNFib, - " value of FIB.cswNew MUST be ", - strExpectedCswNew + ", not 0x", Integer.toHexString( cswNew ) ); + LOG.atWarn().log("Since FIB.nFib == {} value of FIB.cswNew MUST be {}, not 0x{}", strNFib, strExpectedCswNew, Integer.toHexString(cswNew)); } public void fillVariableFields( byte[] mainDocument, byte[] tableStream ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java index b5d28d1f45..8fba06f82b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java @@ -20,12 +20,12 @@ package org.apache.poi.hwpf.model; import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * FontTable or in MS terminology sttbfffn is a common data structure written in all @@ -38,7 +38,7 @@ import org.apache.poi.util.POILogger; @Internal public final class FontTable { - private static final POILogger LOG = POILogFactory.getLogger(FontTable.class); + private static final Logger LOG = LogManager.getLogger(FontTable.class); private short _stringCount;// how many strings are included in the string table private short _extraDataSz;// size in bytes of the extra data @@ -93,7 +93,7 @@ public final class FontTable { if(chpFtc >= _stringCount) { - LOG.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); + LOG.atInfo().log("Mismatch in chpFtc with stringCount"); return null; } @@ -104,7 +104,7 @@ public final class FontTable { if(chpFtc >= _stringCount) { - LOG.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); + LOG.atInfo().log("Mismatch in chpFtc with stringCount"); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java index 36b069d80a..f13e9a3884 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java @@ -19,11 +19,13 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.types.LVLFAbstractType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * "The LVL structure contains formatting information about a specific level in @@ -43,7 +45,7 @@ public final class ListLevel //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 10_485_760; - private static final POILogger LOG = POILogFactory.getLogger( ListLevel.class ); + private static final Logger LOG = LogManager.getLogger(ListLevel.class); private byte[] _grpprlChpx; private byte[] _grpprlPapx; @@ -244,10 +246,7 @@ public final class ListLevel { if ( _xst.getCch() != 1 ) { - LOG.log( POILogger.WARN, "LVL at offset ", - Integer.valueOf( startOffset ), - " has nfc == 0x17 (bullets), but cch != 1 (", - Integer.valueOf( _xst.getCch() ), ")" ); + LOG.atWarn().log("LVL at offset {} has nfc == 0x17 (bullets), but cch != 1 ({})", box(startOffset),box(_xst.getCch())); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java index b105fc16e7..e163b2f005 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java @@ -23,17 +23,19 @@ import java.util.LinkedHashMap; import java.util.NoSuchElementException; import java.util.Objects; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.types.LSTFAbstractType; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; @Internal public final class ListTables { - private static final POILogger log = POILogFactory.getLogger(ListTables.class); + private static final Logger LOGGER = LogManager.getLogger(ListTables.class); /** * Both PlfLst and the following LVLs @@ -141,13 +143,13 @@ public final class ListTables { ListData lst = _listMap.get(lsid); if (lst == null) { - log.log(POILogger.WARN, "ListData for ", lsid, " was null."); + LOGGER.atWarn().log("ListData for {} was null.", box(lsid)); return null; } if(level < lst.numLevels()) { return lst.getLevels()[level]; } - log.log(POILogger.WARN, "Requested level ", level, " which was greater than the maximum defined (", lst.numLevels(), ")"); + LOGGER.atWarn().log("Requested level {} which was greater than the maximum defined ({})", box(level),box(lst.numLevels())); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java index 4f49fe90c7..3377c8cd9c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java @@ -18,16 +18,18 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static java.lang.Integer.toHexString; +import static org.apache.logging.log4j.util.Unbox.box; public class NilPICFAndBinData { - private static final POILogger log = POILogFactory - .getLogger( NilPICFAndBinData.class ); + private static final Logger LOGGER = LogManager.getLogger(NilPICFAndBinData.class); private byte[] _binData; @@ -44,9 +46,7 @@ public class NilPICFAndBinData if ( cbHeader != 0x44 ) { - log.log(POILogger.WARN, "NilPICFAndBinData at offset ", offset, - " cbHeader 0x", Integer.toHexString(cbHeader), " != 0x44" - ); + LOGGER.atWarn().log("NilPICFAndBinData at offset {} cbHeader 0x{} != 0x44", box(offset), toHexString(cbHeader)); } // skip the 62 ignored bytes diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldFfn.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldFfn.java index 27e5de7b1b..38c0d53cab 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldFfn.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldFfn.java @@ -19,20 +19,22 @@ package org.apache.poi.hwpf.model; import java.nio.charset.Charset; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Word 6.0 Font information */ @Internal public final class OldFfn { - private static final POILogger LOG = POILogFactory.getLogger(OldFfn.class); + private static final Logger LOG = LogManager.getLogger(OldFfn.class); private final byte _chs;// character set identifier @@ -59,7 +61,7 @@ public final class OldFfn { short fontDescriptionLength = buf[offset]; offset += 1; if (offset + fontDescriptionLength > fontTableEnd) { - LOG.log(POILogger.WARN, "Asked to read beyond font table end. Skipping font"); + LOG.atWarn().log("Asked to read beyond font table end. Skipping font"); return null; } @@ -69,7 +71,7 @@ public final class OldFfn { Charset charset = null; FontCharset wmfCharset = FontCharset.valueOf(chs & 0xff); if (wmfCharset == null) { - LOG.log(POILogger.WARN, "Couldn't find font for type: ", (chs & 0xff)); + LOG.atWarn().log("Couldn't find font for type: {}", box((chs & 0xff))); } else { charset = wmfCharset.getCharset(); } @@ -88,7 +90,7 @@ public final class OldFfn { } } if (fontNameLength == -1) { - LOG.log(POILogger.WARN, "Couldn't find the zero-byte delimited font name length"); + LOG.atWarn().log("Couldn't find the zero-byte delimited font name length"); return null; } String fontName = new String(buf, offset, fontNameLength, charset); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java index 0e3ec37815..d4935a1ba6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java @@ -21,18 +21,18 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Font table for Word 6.0 */ @Internal public final class OldFontTable { - private static final POILogger LOG = POILogFactory.getLogger(OldFontTable.class); + private static final Logger LOG = LogManager.getLogger(OldFontTable.class); // added extra facilitator members // FFN structure containing strings of font names @@ -69,7 +69,7 @@ public final class OldFontTable { public String getMainFont(int chpFtc) { if (chpFtc >= _fontNames.length) { - LOG.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); + LOG.atInfo().log("Mismatch in chpFtc with stringCount"); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index 25dae0de7d..675b62e8be 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -26,14 +26,17 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.hwpf.sprm.SprmIterator; import org.apache.poi.hwpf.sprm.SprmOperation; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static java.lang.System.currentTimeMillis; +import static org.apache.logging.log4j.util.Unbox.box; /** * This class represents the bin table of Word document but it also serves as a @@ -43,7 +46,7 @@ import org.apache.poi.util.POILogger; @Internal public class PAPBinTable { - private static final POILogger LOG = POILogFactory.getLogger( PAPBinTable.class ); + private static final Logger LOG = LogManager.getLogger(PAPBinTable.class); protected final ArrayList<PAPX> _paragraphs = new ArrayList<>(); @@ -55,7 +58,7 @@ public class PAPBinTable byte[] dataStream, int offset, int size, CharIndexTranslator charIndexTranslator ) { - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); { PlexOfCps binTable = new PlexOfCps( tableStream, offset, size, 4 ); @@ -80,13 +83,11 @@ public class PAPBinTable } } - LOG.log( POILogger.DEBUG, "PAPX tables loaded in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms (", - Integer.valueOf( _paragraphs.size() ), " elements)" ); + LOG.atDebug().log("PAPX tables loaded in {} ms ({} elements)", box(currentTimeMillis() - start),box(_paragraphs.size())); if ( _paragraphs.isEmpty() ) { - LOG.log( POILogger.WARN, "PAPX FKPs are empty" ); + LOG.atWarn().log("PAPX FKPs are empty"); _paragraphs.add( new PAPX( 0, 0, new SprmBuffer( 2 ) ) ); } } @@ -100,7 +101,7 @@ public class PAPBinTable static void rebuild( final StringBuilder docText, ComplexFileTable complexFileTable, List<PAPX> paragraphs ) { - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); if ( complexFileTable != null ) { @@ -117,8 +118,7 @@ public class PAPBinTable if ( igrpprl < 0 || igrpprl >= sprmBuffers.length ) { - LOG.log( POILogger.WARN, textPiece - + "'s PRM references to unknown grpprl" ); + LOG.atWarn().log("{}'s PRM references to unknown grpprl", textPiece); continue; } @@ -146,20 +146,15 @@ public class PAPBinTable } } - LOG.log( POILogger.DEBUG, - "Merged (?) with PAPX from complex file table in ", - Long.valueOf( System.currentTimeMillis() - start ), - " ms (", Integer.valueOf( paragraphs.size() ), - " elements in total)" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("Merged (?) with PAPX from complex file table in {} ms ({} elements in total)", box(currentTimeMillis() - start),box(paragraphs.size())); + start = currentTimeMillis(); } List<PAPX> oldPapxSortedByEndPos = new ArrayList<>(paragraphs); oldPapxSortedByEndPos.sort(PropertyNode.EndComparator); - LOG.log( POILogger.DEBUG, "PAPX sorted by end position in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("PAPX sorted by end position in {} ms", box(currentTimeMillis() - start)); + start = currentTimeMillis(); final Map<PAPX, Integer> papxToFileOrder = new IdentityHashMap<>(); { @@ -179,9 +174,8 @@ public class PAPBinTable } }; - LOG.log( POILogger.DEBUG, "PAPX's order map created in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms" ); - start = System.currentTimeMillis(); + LOG.atDebug().log("PAPX's order map created in {} ms", box(currentTimeMillis() - start)); + start = currentTimeMillis(); List<PAPX> newPapxs = new LinkedList<>(); int lastParStart = 0; @@ -223,10 +217,7 @@ public class PAPBinTable if ( papxs.size() == 0 ) { - LOG.log( POILogger.WARN, "Paragraph [", - Integer.valueOf( startInclusive ), "; ", - Integer.valueOf( endExclusive ), - ") has no PAPX. Creating new one." ); + LOG.atWarn().log("Paragraph [{}; {}) has no PAPX. Creating new one.", box(startInclusive),box(endExclusive)); // create it manually PAPX papx = new PAPX( startInclusive, endExclusive, new SprmBuffer( 2 ) ); @@ -273,9 +264,7 @@ public class PAPBinTable paragraphs.clear(); paragraphs.addAll( newPapxs ); - LOG.log( POILogger.DEBUG, "PAPX rebuilded from document text in ", - Long.valueOf( System.currentTimeMillis() - start ), " ms (", - Integer.valueOf( paragraphs.size() ), " elements)" ); + LOG.atDebug().log("PAPX rebuilded from document text in {} ms ({} elements)", box(currentTimeMillis() - start),box(paragraphs.size())); } public void insert(int listIndex, int cpStart, SprmBuffer buf) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java index bf904e4738..c5e8e0da78 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java @@ -17,9 +17,12 @@ package org.apache.poi.hwpf.model; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBlipRecord; @@ -31,8 +34,8 @@ import org.apache.poi.hwpf.usermodel.Picture; import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * Holds information about all pictures embedded in Word Document either via "Insert -> Picture -> From File" or via @@ -53,9 +56,9 @@ import org.apache.poi.util.POILogger; */ @Internal public final class PicturesTable { - private static final POILogger LOG = POILogFactory.getLogger( PicturesTable.class ); + private static final Logger LOG = LogManager.getLogger(PicturesTable.class); - static final int TYPE_IMAGE = 0x08; + static final int TYPE_IMAGE = 0x08; static final int TYPE_IMAGE_WORD2000 = 0x00; static final int TYPE_IMAGE_PASTED_FROM_CLIPBOARD = 0xA; static final int TYPE_IMAGE_PASTED_FROM_CLIPBOARD_WORD2000 = 0x2; @@ -151,9 +154,9 @@ public final class PicturesTable { * @param run * @param fillBytes if true, Picture will be returned with filled byte array that represent picture's contents. If you don't want * to have that byte array in memory but only write picture's contents to stream, pass false and then use Picture.writeImageContent - * @see Picture#writeImageContent(java.io.OutputStream) + * @see Picture#writeImageContent(OutputStream) * @return a Picture object if picture exists for specified CharacterRun, null otherwise. PicturesTable.hasPicture is used to determine this. - * @see #hasPicture(org.apache.poi.hwpf.usermodel.CharacterRun) + * @see #hasPicture(CharacterRun) */ public Picture extractPicture(CharacterRun run, boolean fillBytes) { if (hasPicture(run)) { @@ -198,10 +201,7 @@ public final class PicturesTable { } catch ( Exception exc ) { - LOG.log( - POILogger.WARN, - "Unable to load picture from BLIB record at offset #", - Integer.valueOf( bse.getOffset() ), exc ); + LOG.atWarn().withThrowable(exc).log("Unable to load picture from BLIP record at offset #{}", box(bse.getOffset())); } } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PlfLfo.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PlfLfo.java index dbe32463e6..b2adc51ef1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PlfLfo.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PlfLfo.java @@ -23,11 +23,13 @@ import java.io.IOException; import java.util.Arrays; import java.util.NoSuchElementException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.types.LFOAbstractType; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * The PlfLfo structure contains the list format override data for the document. @@ -39,7 +41,7 @@ import org.apache.poi.util.POILogger; */ public class PlfLfo { - private static final POILogger log = POILogFactory.getLogger( PlfLfo.class ); + private static final Logger LOGGER = LogManager.getLogger(PlfLfo.class); /** * An unsigned integer that specifies the count of elements in both the @@ -107,11 +109,7 @@ public class PlfLfo if ( ( offset - fcPlfLfo ) != lcbPlfLfo ) { - if (log.check(POILogger.WARN)) { - log.log(POILogger.WARN, "Actual size of PlfLfo is " - + (offset - fcPlfLfo) + " bytes, but expected " - + lcbPlfLfo); - } + LOGGER.atWarn().log("Actual size of PlfLfo is {} bytes, but expected {}", box(offset - fcPlfLfo),box(lcbPlfLfo)); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java index 4746799d44..7784e41255 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java @@ -21,10 +21,12 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Objects; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.Duplicatable; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; /** * Represents a lightweight node in the Trees used to store content @@ -40,7 +42,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara public static final Comparator<PropertyNode<?>> StartComparator = Comparator.comparingInt(PropertyNode::getStart); - private static final POILogger LOG = POILogFactory.getLogger(PropertyNode.class); + private static final Logger LOG = LogManager.getLogger(PropertyNode.class); protected Object _buf; @@ -72,13 +74,12 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara _buf = buf; if (_cpStart < 0) { - LOG.log(POILogger.WARN, "A property claimed to start before zero, at ", _cpStart, "! Resetting it to zero, and hoping for the best"); + LOG.atWarn().log("A property claimed to start before zero, at {}! Resetting it to zero, and hoping for the best", box(_cpStart)); _cpStart = 0; } if (_cpEnd < _cpStart) { - LOG.log(POILogger.WARN, "A property claimed to end (", _cpEnd, - ") before start! Resetting end to start, and hoping for the best"); + LOG.atWarn().log("A property claimed to end ({}) before start! Resetting end to start, and hoping for the best", box(_cpEnd)); _cpEnd = _cpStart; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index 4656ec8de1..547960c185 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -22,13 +22,13 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; @Internal public class SectionTable @@ -37,7 +37,7 @@ public class SectionTable //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; - private static final POILogger LOG = POILogFactory.getLogger(SectionTable.class); + private static final Logger LOG = LogManager.getLogger(SectionTable.class); private static final int SED_SIZE = 12; protected List<SEPX> _sections = new ArrayList<>(); @@ -100,7 +100,7 @@ public class SectionTable } } if(! matchAt && matchHalf) { - LOG.log(POILogger.WARN, "Your document seemed to be mostly unicode, but the section definition was in bytes! Trying anyway, but things may well go wrong!"); + LOG.atWarn().log("Your document seemed to be mostly unicode, but the section definition was in bytes! Trying anyway, but things may well go wrong!"); for(int i=0; i<_sections.size(); i++) { SEPX s = _sections.get(i); GenericPropertyNode node = sedPlex.getProperty(i); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java index 385650b32d..85343ee242 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java @@ -18,10 +18,9 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; +import org.apache.logging.log4j.LogManager; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -81,11 +80,11 @@ public class Sttb if ( ffff != (short) 0xffff ) { - POILogFactory.getLogger(Sttb.class).log( - POILogger.WARN, - "Non-extended character Pascal strings are not supported right now. ", - "Creating empty values in the RevisionMarkAuthorTable for now. ", - "Please, contact POI developers for update."); + LogManager.getLogger(Sttb.class).atWarn().log( + "Non-extended character Pascal strings are not supported right now. " + + "Creating empty values in the RevisionMarkAuthorTable for now. " + + "Please, contact POI developers for update." + ); //set data and extraData to empty values to avoid //downstream NPE in case someone calls getEntries on RevisionMarkAuthorTable _data = new String[0]; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java index 7dcc6e5f4a..05b2c04677 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java @@ -20,6 +20,8 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; import java.util.Objects; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.types.StdfBaseAbstractType; import org.apache.poi.hwpf.usermodel.CharacterProperties; import org.apache.poi.hwpf.usermodel.ParagraphProperties; @@ -27,10 +29,10 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Comment me * @@ -39,7 +41,7 @@ import org.apache.poi.util.StringUtil; @Internal public final class StyleDescription { - private static final POILogger LOG = POILogFactory.getLogger(StyleDescription.class); + private static final Logger LOG = LogManager.getLogger(StyleDescription.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; @@ -74,7 +76,7 @@ public final class StyleDescription { } else if (baseLength == 0x000A) { readStdfPost2000 = false; } else { - LOG.log(POILogger.WARN, "Style definition has non-standard size of ", baseLength); + LOG.atWarn().log("Style definition has non-standard size of {}", box(baseLength)); } _stdfBase = new StdfBase(std, offset); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index e40be66f31..cd885b9556 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -25,11 +25,14 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static java.lang.System.currentTimeMillis; +import static org.apache.logging.log4j.util.Unbox.box; /** * The piece table for matching up character positions to bits of text. This @@ -40,7 +43,7 @@ import org.apache.poi.util.POILogger; */ @Internal public class TextPieceTable implements CharIndexTranslator { - private static final POILogger LOG = POILogFactory.getLogger(TextPieceTable.class); + private static final Logger LOG = LogManager.getLogger(TextPieceTable.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000_000; @@ -277,7 +280,7 @@ public class TextPieceTable implements CharIndexTranslator { } public StringBuilder getText() { - final long start = System.currentTimeMillis(); + final long start = currentTimeMillis(); // rebuild document paragraphs structure StringBuilder docText = new StringBuilder(); @@ -286,23 +289,14 @@ public class TextPieceTable implements CharIndexTranslator { int toAppendLength = toAppend.length(); if (toAppendLength != textPiece.getEnd() - textPiece.getStart()) { - LOG.log( - POILogger.WARN, - "Text piece has boundaries [", - textPiece.getStart(), - "; ", - textPiece.getEnd(), - ") but length ", - textPiece.getEnd() - textPiece.getStart()); + LOG.atWarn().log("Text piece has boundaries [{}; {}) but length {}", box(textPiece.getStart()),box(textPiece.getEnd()),box(textPiece.getEnd() - textPiece.getStart())); } docText.replace(textPiece.getStart(), textPiece.getStart() + toAppendLength, toAppend); } - LOG.log(POILogger.DEBUG, "Document text were rebuilded in ", - System.currentTimeMillis() - start, " ms (", - docText.length(), " chars)"); + LOG.atDebug().log("Document text were rebuilt in {} ms ({} chars)", box(currentTimeMillis() - start),box(docText.length())); return docText; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java index 242fb6755c..34acfb99dc 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java @@ -16,16 +16,18 @@ ==================================================================== */ package org.apache.poi.hwpf.model; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; @Internal public class Xstz { - private static final POILogger log = POILogFactory.getLogger( Xstz.class ); + private static final Logger LOGGER = LogManager.getLogger(Xstz.class); private final short _chTerm = 0; private Xst _xst; @@ -50,10 +52,7 @@ public class Xstz short term = LittleEndian.getShort( data, offset ); if ( term != 0 ) { - if (log.check(POILogger.WARN)) { - log.log(POILogger.WARN, "chTerm at the end of Xstz at offset ", - offset, " is not 0"); - } + LOGGER.atWarn().log("chTerm at the end of Xstz at offset {} is not 0", box(offset)); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java index 27ad6e8041..bad4429041 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -17,6 +17,8 @@ package org.apache.poi.hwpf.sprm; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.usermodel.ShadingDescriptor80; import org.apache.poi.hwpf.model.Colorref; @@ -28,15 +30,13 @@ import org.apache.poi.hwpf.usermodel.DateAndTime; import org.apache.poi.hwpf.usermodel.ShadingDescriptor; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; @Internal public final class CharacterSprmUncompressor extends SprmUncompressor { - private static final POILogger LOG = POILogFactory.getLogger( CharacterSprmUncompressor.class ); + private static final Logger LOG = LogManager.getLogger(CharacterSprmUncompressor.class); - public CharacterSprmUncompressor() + public CharacterSprmUncompressor() { } @@ -77,8 +77,7 @@ public final class CharacterSprmUncompressor extends SprmUncompressor } catch ( Exception exc ) { - LOG.log( POILogger.ERROR, "Unable to apply all style ", - style, " CHP SPRMs to CHP: ", exc, exc ); + LOG.atError().withThrowable(exc).log("Unable to apply all style {} CHP SPRMs to CHP", style); } } @@ -91,8 +90,7 @@ public final class CharacterSprmUncompressor extends SprmUncompressor } catch ( Exception exc ) { - LOG.log( POILogger.ERROR, - "Unable to process all direct CHP SPRMs: ", exc, exc ); + LOG.atError().withThrowable(exc).log("Unable to process all direct CHP SPRMs"); } return newProperties; } @@ -111,8 +109,7 @@ public final class CharacterSprmUncompressor extends SprmUncompressor { if ( warnAboutNonChpSprms ) { - LOG.log( POILogger.WARN, - "Non-CHP SPRM returned by SprmIterator: ", sprm ); + LOG.atWarn().log("Non-CHP SPRM returned by SprmIterator: {}", sprm); } continue; } @@ -140,8 +137,7 @@ public final class CharacterSprmUncompressor extends SprmUncompressor } catch ( Exception exc ) { - LOG.log( POILogger.ERROR, - "Unable to extract istd from direct CHP SPRM: ", exc, exc ); + LOG.atError().withThrowable(exc).log("Unable to extract istd from direct CHP SPRM"); } return style; } @@ -705,7 +701,7 @@ public final class CharacterSprmUncompressor extends SprmUncompressor oldCHP.isFNoProof())); break; default: - LOG.log( POILogger.DEBUG, "Unknown CHP sprm ignored: ", sprm ); + LOG.atDebug().log("Unknown CHP sprm ignored: {}", sprm); break; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index fc3915d600..d1d41919fc 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.model.TabDescriptor; import org.apache.poi.hwpf.model.types.TBDAbstractType; import org.apache.poi.hwpf.usermodel.BorderCode; @@ -36,13 +38,13 @@ import org.apache.poi.hwpf.usermodel.ShadingDescriptor80; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; @Internal public final class ParagraphSprmUncompressor extends SprmUncompressor { - private static final POILogger LOG = POILogFactory.getLogger( ParagraphSprmUncompressor.class ); + private static final Logger LOG = LogManager.getLogger(ParagraphSprmUncompressor.class); public ParagraphSprmUncompressor() { @@ -69,9 +71,7 @@ public final class ParagraphSprmUncompressor extends SprmUncompressor { } catch ( Exception exc ) { - LOG.log( - POILogger.ERROR, - "Unable to apply SPRM operation '", sprm.getOperation(), "': ", exc ); + LOG.atError().withThrowable(exc).log("Unable to apply SPRM operation '{}'", box(sprm.getOperation())); } } } @@ -411,7 +411,7 @@ public final class ParagraphSprmUncompressor extends SprmUncompressor { newPAP.setRsid( sprm.getOperand() ); break; default: - LOG.log( POILogger.DEBUG, "Unknown PAP sprm ignored: ", sprm ); + LOG.atDebug().log("Unknown PAP sprm ignored: {}", sprm); break; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java index a51f7c779f..68375bb443 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java @@ -19,18 +19,20 @@ package org.apache.poi.hwpf.sprm; import java.util.Arrays; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.SectionProperties; -import org.apache.poi.util.HexDump; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; +import static org.apache.poi.util.HexDump.byteToHex; @Internal public final class SectionSprmUncompressor extends SprmUncompressor { - private static final POILogger LOG = POILogFactory.getLogger(SectionSprmUncompressor.class); + private static final Logger LOG = LogManager.getLogger(SectionSprmUncompressor.class); public SectionSprmUncompressor() { @@ -241,7 +243,7 @@ public final class SectionSprmUncompressor extends SprmUncompressor { newSEP.setNfcEdnRef(sprm.getOperand()); break; default: - LOG.log(POILogger.INFO, "Unsupported Sprm operation: ", operation, " (", HexDump.byteToHex(operation), ")"); + LOG.atInfo().log("Unsupported Sprm operation: {} ({})", box(operation), byteToHex(operation)); break; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java index 0332ae37ae..9feb5057a3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java @@ -17,18 +17,18 @@ package org.apache.poi.hwpf.sprm; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.TableCellDescriptor; import org.apache.poi.hwpf.usermodel.TableProperties; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; @Internal public final class TableSprmUncompressor extends SprmUncompressor { - private static final POILogger LOG = POILogFactory.getLogger( TableSprmUncompressor.class ); + private static final Logger LOG = LogManager.getLogger(TableSprmUncompressor.class); public TableSprmUncompressor() { @@ -48,8 +48,7 @@ public final class TableSprmUncompressor extends SprmUncompressor { } else { - LOG.log( POILogger.WARN, - "Some table rows didn't specify number of columns in SPRMs" ); + LOG.atWarn().log("Some table rows didn't specify number of columns in SPRMs"); tableProperties = new TableProperties( (short) 1 ); } @@ -69,8 +68,7 @@ public final class TableSprmUncompressor extends SprmUncompressor { } catch ( ArrayIndexOutOfBoundsException ex ) { - LOG.log( POILogger.ERROR, "Unable to apply ", sprm, - ": ", ex, ex ); + LOG.atError().withThrowable(ex).log("Unable to apply {}", sprm); } } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java index 27389f42c3..e5d1395f75 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -19,6 +19,8 @@ package org.apache.poi.hwpf.usermodel; import java.util.NoSuchElementException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.model.LFO; @@ -30,11 +32,11 @@ import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.hwpf.sprm.TableSprmCompressor; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; public class Paragraph extends Range implements Duplicatable { - private static final POILogger log = POILogFactory.getLogger( Paragraph.class ); + private static final Logger LOGGER = LogManager.getLogger(Paragraph.class); public static final short SPRM_JC = 0x2403; public static final short SPRM_FSIDEBYSIDE = 0x2404; @@ -118,8 +120,7 @@ public class Paragraph extends Range implements Duplicatable { } catch ( NoSuchElementException exc ) { - log.log( POILogger.WARN, "Paragraph refers to LFO #", - properties.getIlfo(), " that does not exists" ); + LOGGER.atWarn().log("Paragraph refers to LFO #{} that does not exists", box(properties.getIlfo())); } if ( lfo != null ) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java index c91a38f341..315e0be475 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; import java.util.zip.InflaterInputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBlipRecord; import org.apache.poi.ddf.EscherComplexProperty; @@ -35,16 +37,13 @@ import org.apache.poi.ddf.EscherRecord; import org.apache.poi.hwpf.model.PICF; import org.apache.poi.hwpf.model.PICFAndOfficeArtData; import org.apache.poi.sl.image.ImageHeaderPNG; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** * Represents embedded picture extracted from Word Document */ public final class Picture { - private static final POILogger log = POILogFactory - .getLogger( Picture.class ); + private static final Logger LOGGER = LogManager.getLogger(Picture.class); private static final byte[] COMPRESSED1 = { (byte) 0xFE, 0x78, (byte) 0xDA }; @@ -161,9 +160,7 @@ public final class Picture { * Problems reading from the actual ByteArrayInputStream should * never happen so this will only ever be a ZipException. */ - log.log( POILogger.INFO, - "Possibly corrupt compression or non-compressed data", - e ); + LOGGER.atInfo().withThrowable(e).log("Possibly corrupt compression or non-compressed data"); } } else diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index 73517238a0..0b6cbcb644 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -18,9 +18,12 @@ package org.apache.poi.hwpf.usermodel; import static java.util.stream.Collectors.toList; +import static org.apache.logging.log4j.util.Unbox.box; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.model.CHPX; @@ -37,8 +40,6 @@ import org.apache.poi.util.DocumentFormatException; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * This class is the central class of the HWPF object model. All properties that @@ -53,9 +54,9 @@ import org.apache.poi.util.POILogger; */ public class Range { - private static final POILogger LOG = POILogFactory.getLogger( Range.class ); + private static final Logger LOG = LogManager.getLogger(Range.class); - /** + /** * @deprecated POI 3.8 beta 5 */ @Deprecated @@ -824,10 +825,8 @@ public class Range { initAll(); if ( tableEndInclusive >= this._parEnd ) { - LOG.log( POILogger.WARN, "The table's bounds ", "[", - this._parStart, "; ", tableEndInclusive, ")", - " fall outside of this Range paragraphs numbers [", - this._parStart, "; ", this._parEnd, ")" ); + LOG.atWarn().log("The table's bounds [{}; {}) fall outside of this Range paragraphs numbers [{}; {})", + this._parStart, box(tableEndInclusive),box(this._parStart),box(this._parEnd)); } if ( tableEndInclusive < 0 ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java index 30e1d26a21..9e70662ead 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java @@ -20,14 +20,16 @@ package org.apache.poi.hwpf.usermodel; import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.hwpf.sprm.TableSprmUncompressor; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; public final class TableRow extends Range { - private static final POILogger LOG = POILogFactory.getLogger( TableRow.class ); + private static final Logger LOG = LogManager.getLogger(TableRow.class); private static final short SPRM_DXAGAPHALF = (short) 0x9602; private static final short SPRM_DYAROWHEIGHT = (short) 0x9407; @@ -187,11 +189,8 @@ public final class TableRow extends Range if ( cells.size() != expectedCellsCount ) { - LOG.log( POILogger.WARN, - "Number of found table cells (", cells.size(), - ") for table row [", getStartOffset(), "c; ", - getEndOffset(), "c] not equals to stored property value ", - expectedCellsCount ); + LOG.atWarn().log("Number of found table cells ({}) for table row [{}c; {}c] not equals to stored property value {}", + cells.size(), box(getStartOffset()),box(getEndOffset()),box(expectedCellsCount)); _tprops.setItcMac( (short) cells.size() ); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/util/LittleEndianCP950Reader.java b/src/scratchpad/src/org/apache/poi/hwpf/util/LittleEndianCP950Reader.java index 3df94849c7..27f796c11e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/util/LittleEndianCP950Reader.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/util/LittleEndianCP950Reader.java @@ -23,9 +23,10 @@ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharsetDecoder; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.SimpleMessage; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Stream that converts CP950 (MSOffice's dialect of Big5), with @@ -34,7 +35,7 @@ import org.apache.poi.util.POILogger; @Internal public class LittleEndianCP950Reader extends Reader { - private static final POILogger LOGGER = POILogFactory.getLogger(LittleEndianCP950Reader.class); + private static final Logger LOGGER = LogManager.getLogger(LittleEndianCP950Reader.class); private static final char UNMAPPABLE = '?'; private final ByteBuffer doubleByteBuffer = ByteBuffer.allocate(2); @@ -107,9 +108,9 @@ public class LittleEndianCP950Reader extends Reader { charBuffer.flip(); if (charBuffer.length() == 0) { - LOGGER.log(POILogger.WARN, "couldn't create char for: " + LOGGER.atWarn().log(() -> new SimpleMessage("couldn't create char for: " + Integer.toString((leading & 0xff), 16) - + " " + Integer.toString((trailing & 0xff), 16)); + + " " + Integer.toString((trailing & 0xff), 16))); return UNMAPPABLE; } else { return Character.codePointAt(charBuffer, 0); @@ -475,8 +476,9 @@ public class LittleEndianCP950Reader extends Reader { case 0xfe: return 0x2593; default: - LOGGER.log(POILogger.WARN, "couldn't create char for: f9" - + " " + Integer.toString((trailing & 0xff), 16)); + LOGGER.atWarn().log(() -> + new SimpleMessage("couldn't create char for: f9 " + Integer.toString((trailing & 0xff), 16)) + ); return UNMAPPABLE; } } diff --git a/src/scratchpad/testcases/commons-logging.properties b/src/scratchpad/testcases/commons-logging.properties deleted file mode 100644 index 3b4d40d05e..0000000000 --- a/src/scratchpad/testcases/commons-logging.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
-log4j.configuration=log4j.properties
\ No newline at end of file diff --git a/src/scratchpad/testcases/log4j.properties b/src/scratchpad/testcases/log4j.properties deleted file mode 100644 index 23d316d79c..0000000000 --- a/src/scratchpad/testcases/log4j.properties +++ /dev/null @@ -1,23 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -log4j.rootLogger=ALL,CONSOLE - -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.target=System.out -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c %5p %m%n - -log4j.logger.org.apache.fontbox.ttf=INFO diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java index b4efb828d3..142ad026e4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java @@ -22,15 +22,17 @@ import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipInputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.POIDataSamples; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; + +import static org.apache.logging.log4j.util.Unbox.box; public class HWPFTestDataSamples { - private static final POILogger LOG = POILogFactory.getLogger( HWPFTestDataSamples.class ); + private static final Logger LOG = LogManager.getLogger(HWPFTestDataSamples.class); public static HWPFDocument openSampleFile(String sampleFileName) { try { @@ -65,16 +67,13 @@ public class HWPFTestDataSamples { final long endUnzip = System.currentTimeMillis(); byte[] byteArray = baos.toByteArray(); - LOG.log(POILogger.DEBUG, "Unzipped in ", - Long.valueOf(endUnzip - start), " ms -- ", - Long.valueOf(byteArray.length), " byte(s)"); + LOG.atDebug().log("Unzipped in {} ms -- {} byte(s)", box(endUnzip - start),box(byteArray.length)); ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); HWPFDocument doc = new HWPFDocument(bais); final long endParse = System.currentTimeMillis(); - LOG.log(POILogger.DEBUG, "Parsed in ", - Long.valueOf(endParse - start), " ms"); + LOG.atDebug().log("Parsed in {} ms", box(endParse - start)); return doc; } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java index c30d80169f..be98329282 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java @@ -49,8 +49,6 @@ import org.apache.poi.hwpf.model.PicturesTable; import org.apache.poi.hwpf.model.SubdocumentType; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; |