Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust Logging level for apache commons logging?

Tags:

I have a simple console app which uses apache's PDFBox library, which in turn uses commons logging. I'm getting a lot of junk messages in my console which I'd like to suppress:

Feb 15, 2011 3:56:40 PM org.apache.pdfbox.util.PDFStreamEngine processOperator INFO: unsupported/disabled operation: EI

In my code, I've tried to reset the log levels to no avail:

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

Despite these settings, the messages are still showing up on the console. Retrieving the log object from Commons logging doesn't help either, since it doesn't seem to have a way to set the level.

Is there a way to suppress these messages programmatically? Or do I need to add a config file?

like image 373
user364902 Avatar asked Feb 15 '11 21:02

user364902


People also ask

How do I increase my logging level?

To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)

How do I set classpath for Apache Commons Logging?

Set CLASSPATH Variable Set the CLASSPATH environment variable to point to the Common Collections jar location. Assuming, you have stored commons-collections4-4.1-bin. zip in Apache folder on various Operating Systems as follows. export CLASSPATH=$CLASSPATH:$APACHE_HOME/commons-collections4-4.1-bin.

Is Apache Commons Logging affected by log4j?

3 Answers. Show activity on this post. Apache Commons Logging is an abstraction for the concrete implementation. It uses log4j, if present and configured.


2 Answers

Commons-logging is only a logging-facade, meaning it doesn't provide the code which actually writes the logdata to e.g., disk. What you need to change is the configuration for the actual logging implementation (such as logback, log4j, etc.). If no such library is found it defaults to java.util.logging.

I would recommend putting e.g., log4j in the classpath and add a log4j.xml configuration file in your classpath. The mere presence of log4j in the classpath is in this case enough to initialize it. Log4j can also be configured programmatically.

like image 157
Johan Sjöberg Avatar answered Oct 01 '22 00:10

Johan Sjöberg


This works for me:

String[] loggers = { "org.apache.pdfbox.util.PDFStreamEngine",         "org.apache.pdfbox.pdmodel.font.PDSimpleFont" }; for (String logger : loggers) {   org.apache.log4j.Logger logpdfengine = org.apache.log4j.Logger          .getLogger(logger);   logpdfengine.setLevel(org.apache.log4j.Level.OFF); } 
like image 29
Wolfgang Fahl Avatar answered Oct 01 '22 00:10

Wolfgang Fahl