Disabling logging messages from org.apache.fontbox and ...pdfbox

1.6k Views Asked by At

I use PDFbox to read PDF files; I understand that it does not use Log4j, it uses apache's common logging (I was surprised to hear this, since its Maven configuration includes Log4j v1).

When I run my program, I get messages like:

18:13:20.093 [SwingWorker-pool-2-thread-1] DEBUG org.apache.fontbox.ttf.PostScriptTable - No PostScript name information is provided for the font CourierNewPS-BoldMT
18:13:20.102 [SwingWorker-pool-2-thread-1] DEBUG org.apache.fontbox.ttf.GlyphSubstitutionTable - Type 4 GSUB lookup table is not supported and will be ignored
18:13:20.102 [SwingWorker-pool-2-thread-1] DEBUG org.apache.fontbox.ttf.GlyphSubstitutionTable - Type 6 GSUB lookup table is not supported and will be ignored
18:13:20.102 [SwingWorker-pool-2-thread-1] DEBUG org.apache.fontbox.ttf.GlyphSubstitutionTable - Type 6 GSUB lookup table is not supported and will be ignored

(68 messages about GlyphSubstitutionTable), and

18:13:20.163 [SwingWorker-pool-2-thread-1] DEBUG org.apache.fontbox.ttf.GlyphSubstitutionTable - Type 4 GSUB lookup table is not supported and will be ignored
18:13:20.476 [Finalizer] DEBUG org.apache.pdfbox.io.ScratchFileBuffer - ScratchFileBuffer not closed!
18:13:23.327 [Finalizer] DEBUG org.apache.pdfbox.io.ScratchFileBuffer - ScratchFileBuffer not closed!

I have tried putting a commons-logging.properties file in src/main/resources containing

org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog

I have tried putting the code java.util.logging.Logger.getLogger("org.apache.pdfbox").setLevel(java.util.logging.Level.OFF) into a static initializer of the class containing the static void main method of my program.

I have tried putting

System.setProperty("org.apache.commons.logging.Log",  "org.apache.commons.logging.impl.NoOpLog");

into that static initializer, separately and together with the previous code.

When I read the PDF in my code, I still get the log messages mentioned above with any and all of the above attempted fixes. How can I eliminate them; I would prefer to just limit them to warning, error, and severe messaages instead of eliminating all messages, but at this point I'll take suggestions for either one.

1

There are 1 best solutions below

1
Alexander Kazakov On
public class Main {
static {
    java.util.logging.Logger.getLogger(
        "org.apache").setLevel(java.util.logging.Level.SEVERE);
}
// ...

has helped me to disable warnings from fontbox also.

While "org.apache.pdfbox" only disables pdfbox warnings, not fontbox ones.

And "org.apache.fontbox" somehow does not disable fontbox warnings.