Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a Java library from printing to the console?

Tags:

java

console

I am using a library that prints a bunch of superfluous information to the console when I reference it. Is there a way to silence the output of the library?

like image 273
dave Avatar asked Mar 08 '10 17:03

dave


People also ask

How do I print without system out Println?

Using the printf() and print() methods The PrintStream class of Java provides two more methods to print data on the console (in addition to the println() method). The print() − This method accepts a single value of any of the primitive or reference data types as a parameter and prints the given value on the console.

How do you print to console in Java?

print(): print() method in Java is used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the end of the text at the console. The next printing takes place from just here.

Which method can you use to print a message to the console in Java?

The print() method is used to print text on the console. It is an overloaded method of the PrintStream class. It accepts a string as a parameter. After printing the statement, the cursor remains on the same line.


1 Answers

If it is using a logging framework (log4j, commons-logging, etc), you can edit/create a properties file to indicate a high logging treshold. in log4j this would look like:

log4j.logger.org.library=error

If the library is using System.out, that's not a good library in the first place. You can change the PrintStream by calling System.setOut(yourDummyPrintStream) (and System.setErr(..)). Your dummy print stream would just swallow the data and not print it anywhere.

like image 130
Bozho Avatar answered Sep 20 '22 03:09

Bozho