Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling logging on PDFBox

Tags:

java

log4j

pdfbox

We are using PDFBox to do some PDF reading and manipulations. But during the parsing, I get a bunch of messages like this one:

Changing font on <m> from <Arial Bold> to the default font

Now how can I disable these? Because a message like this is output on EVERY character of the input if the font is embedded and the log files therefore become pretty unusable.

Now changing the overall log level is not an option, because I need the statements from other components.

I am using Tomcat 5.5, log4j 1.2.16 and pdfbox-app 1.6.0

And here is my log4j config file:

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file.File=/home/PDF/WS/PDF.log
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n

EDIT

After modifying my log4j file, this is how it looks:

# Root logger option
log4j.rootLogger=INFO, file, stdout

log4j.rootLogger.org.apache.pdfbox=ERROR

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file.File=/home/PDF/WS/PDF.log
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n

No matter where I put the log4j.rootLogger.org.apache.pdfbox=ERROR line, errors still keep popping up like this in the log files:

2012-07-16 15:36:46,652 WARN  [font.PDSimpleFont]: Changing font on <r> from <Arial Bold> to the default font
2012-07-16 15:36:46,652 WARN  [font.PDSimpleFont]: Changing font on <o> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN  [font.PDSimpleFont]: Changing font on <c> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN  [font.PDSimpleFont]: Changing font on <e> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN  [font.PDSimpleFont]: Changing font on <s> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN  [font.PDSimpleFont]: Changing font on <u> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN  [font.PDSimpleFont]: Changing font on < > from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN  [font.PDSimpleFont]: Changing font on <P> from <Arial Bold> to the default font

EDIT 2

After consulting log4j: package-specific logging I discovered the right syntax:

log4j.logger.org.apache.pdfbox=ERROR
like image 831
Janis Peisenieks Avatar asked Jul 13 '12 08:07

Janis Peisenieks


People also ask

Does PDFBox use log4j?

Minimum Requirements. The main PDFBox component, pdfbox, has a hard dependency on the commons-logging library. Commons Logging is a generic wrapper around different logging frameworks, so you'll either need to also use a logging library like log4j or let commons-logging fall back to the standard java. util.

What is PDFBox used for?

PDFBox is an open-source library which is written in Java. It supports the development and conversion of PDF Documents. PDFBox Library comes as a JAR file. It allows the creation of new PDF documents, manipulation of existing documents, bookmarking PDF and the ability to extract content from PDF documents.

Is PDFBox open source?

Apache PDFBox is an open source pure-Java library that can be used to create, render, print, split, merge, alter, verify and extract text and meta-data of PDF files.

How to close PDDocument?

You need to call close() on the PDDocument inside the finally block, if you don't then the document will not be closed properly.


2 Answers

Simple way to disable all logging:

java.util.logging.Logger
    .getLogger("org.apache.pdfbox").setLevel(java.util.logging.Level.OFF);

Or if you want to only see the severe messages:

java.util.logging.Logger
    .getLogger("org.apache.pdfbox").setLevel(java.util.logging.Level.SEVERE);
like image 149
Philipp Ludwig Avatar answered Sep 21 '22 05:09

Philipp Ludwig


pdfbox does alot logging on error like you stated before, if you add the following line to the log4j.properties it should clean thing up

log4j.rootLogger.org.apache.pdfbox.pdmodel.font.PDFont=fatal
like image 23
Mark Bakker Avatar answered Sep 18 '22 05:09

Mark Bakker