I'm using java logging to write log messages of my application to a log file and other destinations. Having set the log level to FINE
, I also get (unwanted) messages from AWT/Swing, such as:
{0}, when grabbed {1}, contains {2}
and others. Looking at the JDK source code (see e.g. here), one sees that the name of the corresponding logger is sun.awt.X11.grab.XWindowPeer
.
What I understood from the Java logging framework is that this logging handler should inherit its loglevel from its parents like sun.awt
.
I tried the following:
Logger.getLogger("sun.awt").setLevel(Level.OFF);
but the AWT/Swing debug messages still appear in the log output.
What's the recommended way of programmatically disabling these log messages (while still allowing FINE
messages from other sources) ?
Try Logger.getRootLogger().setLevel(Level.OFF);
I could not find the getRootLogger() method in the Logger class any more. This is what works for me:
If you just want to log the messages of your own application, you can disable all messages and then explicitly enable messages for your application:
Inside the properties-file for logging (e.g. logging.properties) this would be:
I had the same problem today. Searching on google this is the top url and I don't find a good source to a answer, so I will post mine :)
Assuming that Andre use the
java.util.logging
API, it's possible to add aHandler
that will control the format of your log, usingsetFormatter(Formatter newFormatter)
.So I extended
Formatter
and checked if the class of the log contains java.awt, javax.swing or sun.awt.