I'm trying to suppress output of the date line durinng logging when using the default logger in java.util.logging. For example, here is a typical output:
Jun 1, 2010 10:18:12 AM gamma.utility.application info
INFO: ping: db-time=2010-06-01 10:18:12.0, local-time=20100601t101812, duration=180000
Jun 1, 2010 10:21:12 AM gamma.utility.application info
INFO: ping: db-time=2010-06-01 10:21:12.0, local-time=20100601t102112, duration=180000
I would like to get rid of the Jun 1, 2010...
lines, they just clutter my log output. How can I do this?
A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.
From Java SE 7 there is a new system property: java.util.logging.SimpleFormatter.format.
The same property is also configurable on the java.util.logging properties file (logging.properties). If you are an Eclipse user, and you are annoyed by the double line message in the console output, you could change the jre logging.properties file (JDK_HOME/jre/lib/logging.properties) in this way:
java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n
Some example format is available here: http://docs.oracle.com/javase/7/docs/api/index.html?java/util/logging/SimpleFormatter.html.
The problem is caused by a handler in the parent log. The solution is to remove all handlers from the parent log, and then add own custom handler. This code removes handlers from the parent log:
for(Handler iHandler:log.getParent().getHandlers()) { log.getParent().removeHandler(iHandler); }
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