Disabling awt/swing debug (fine) log messages

烈酒焚心 提交于 2019-12-05 02:39:40

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:

Logger.getRootLogger().setLevel(Level.OFF);
Logger.getLogger("package.of.your.application").setLevel(Level.ALL);

Inside the properties-file for logging (e.g. logging.properties) this would be:

.level = OFF
package.of.your.application.level = ALL

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 a Handler that will control the format of your log, using setFormatter(Formatter newFormatter).

So I extended Formatter and checked if the class of the log contains java.awt, javax.swing or sun.awt.

class MyFormatLog extends Formatter {

    @Override
    public String format(LogRecord record) {
        if( !record.getSourceClassName().contains("java.awt") &&
        !record.getSourceClassName().contains("javax.swing.") &&
        !record.getSourceClassName().contains("sun.awt.") ) {
          //format my output...
        } else {
          return "";
        }
    }

}
schwart

I could not find the getRootLogger() method in the Logger class any more. This is what works for me:

logger = Logger.getLogger("my.package");
Logger l = logger;
while (l != null) {
    l.setLevel(Level.OFF);
    l = l.getParent();
}            
logger.setLevel(Level.FINER);
    Logger.getLogger("java.awt").setLevel(Level.OFF);
    Logger.getLogger("sun.awt").setLevel(Level.OFF);
    Logger.getLogger("javax.swing").setLevel(Level.OFF);

Try Logger.getRootLogger().setLevel(Level.OFF);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!