本文介绍了禁用AWT / Swing的调试(精)日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java日志写日志我的应用程序的消息记录到日志文件和其他目的地。已经设置日志级别 FINE ,我也得到(不需要)从AWT / Swing的消息,如:

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}

和其他。纵观JDK源$ C ​​$ C(例如,见) ,人们看到了相应的记录器的名称是 sun.awt.X11.grab.XWindowPeer

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.

我从Java日志框架明白的是,这个记录处理程序应继承其父母的日志级别如 sun.awt

What I understood from the Java logging framework is that this logging handler should inherit its loglevel from its parents like sun.awt.

我试过如下:

Logger.getLogger("sun.awt").setLevel(Level.OFF);

但AWT / Swing的调试消息仍然会出现在日志输出。

but the AWT/Swing debug messages still appear in the log output.

什么是推荐的方式编程禁用这些日志信息(但仍允许从其他渠道 FINE 消息)?

What's the recommended way of programmatically disabling these log messages (while still allowing FINE messages from other sources) ?

推荐答案

如果你只是想记录自己的应用程序的的消息,您可以禁用所有的消息,然后明确启用您的应用程序的消息

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);

里面的属性文件用于记录(例如logging.properties),这将是:

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

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

这篇关于禁用AWT / Swing的调试(精)日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:28