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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With