How do I suppress the date line from 2-line java.util.logging output?

James T picture James T · Oct 27, 2011 · Viewed 7.7k times · Source

I'm using the Java default logger, and right now it's printing a lot of useless trash to the output, here is a example, this line of code:

log.info("Logging pointless information...")

Will output all of this:

Oct 26, 2011 9:37:57 PM java.util.logging.LogManager$RootLogger log
INFO: Logging pointless information...

I don't need to know anything except that second line. How can I remove this trash? All I want is simple text logging.

Answer

Trevor Robinson picture Trevor Robinson · May 22, 2012

Maybe this was added later, but at least with Java 7, java.util.logging.SimpleFormatter supports getting its format from a system property. This JVM argument will print just the second line:

-Djava.util.logging.SimpleFormatter.format='%4$s: %5$s%6$s%n'

Personally, I like to keep all the date/source info, but get rid of the newline (and use a more compact, international date format):

-Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'