我需要以编程方式为某些JDK7内部类启用日志记录.
这是我在我的应用程序初始化中所做的事情:
httpLogger = Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
httpLogger.setLevel(Level.FINEST);
Run Code Online (Sandbox Code Playgroud)
哪里httpLogger是强引用(为了避免记录器被垃圾收集).我还将ConsoleHandler的级别设置为ALL.但是我无法获得任何输出.
如果我通过记录配置文件来执行它,它按预期工作.
我可能错了,但我认为这与我有所关系,不了解PlatformLoggerJava 7中引入的内容,以及 - afaik - 现在用于所有JDK内部日志记录.或许我只是不太了解JUL.
我猜它会起作用,如果我这样做:
httpLogger = PlatformLogger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
httpLogger.setLevel(Level.FINEST);
Run Code Online (Sandbox Code Playgroud)
但是PlatformLogger类是在一个我无法参考的包中.
PlatformLogger?这是JavaDoc:
Platform logger provides an API for the JRE components to log
messages. This enables the runtime components to eliminate the
static dependency of the logging facility and also defers the
java.util.logging initialization until it is enabled.
In addition, the PlatformLogger API can be used if the logging
module does not …Run Code Online (Sandbox Code Playgroud)