Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing PDFBox Logging Level

I'm currently trying and failing to lower the logging level for the PDFBox 1.8.6 library I'm using in my java project. Based on this previous question, I have the following log4j.properties file located in the /src/ directory.

log4j.rootLogger=ERROR, stdout

log4j.logger.org.apache.pdfbox=ERROR

# 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

I'm not sure what else I'm missing, because I'm still being spammed with messages like the following in console.

Jul 10, 2014 10:19:23 AM org.apache.pdfbox.pdfparser.PDFParser parseXrefTable
WARNING: Count in xref table is 0 at offset 223265
Jul 10, 2014 10:19:23 AM org.apache.pdfbox.pdfparser.PDFParser parseXrefTable
WARNING: Count in xref table is 0 at offset 223265
Jul 10, 2014 10:19:23 AM org.apache.pdfbox.pdfparser.PDFParser parseXrefTable
WARNING: Count in xref table is 0 at offset 223265

If there's a way to change the log level programmatically, I'm not attached to the properties file at all since I don't use log4j anywhere else. I don't know if it's even using the log4j.properties file at all. I'm using Eclipse, I'm not certain how to confirm that the log4j.properties file is on the classpath as intended.

like image 694
user3670023 Avatar asked Dec 05 '25 03:12

user3670023


1 Answers

I was having the same problem until I figured it out.

The PDFBox 1.8.6 library doesn't use Log4j directly. Instead it uses Apache Commons Logging Framework (http://commons.apache.org/proper/commons-logging/guide.html).

The commons logging framework has it's own property file to configure logging and only uses log4j as a fallback if it is on the classpath.

To fix this you can either configure the apache commons logging to ignore it or add log4j to your classpath. I found some instructions here, but I wasn't able to get them to work (http://cyntech.wordpress.com/2009/01/09/how-to-use-commons-logging/)

What I finally ended up doing was to add the log4j.jar to my classpath and then the instructions above (add a log4j.properties file in your classpath, with contents log4j.rootLogger=ERROR, stdout) finally worked.

like image 90
Doug Beleznay Avatar answered Dec 07 '25 23:12

Doug Beleznay