JDK: как программно включить PlatformLogger

Мне нужно включить ведение журнала для некоторого внутреннего класса JDK7 программно.

Вот что я делаю при инициализации моего приложения:

httpLogger = Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
httpLogger.setLevel(Level.FINEST);

гдеhttpLogger является сильной ссылкой (во избежание сбора мусора регистратором). Я также установил уровень ConsoleHandler на ВСЕ. Однако я не могу получить какой-либо вывод.

Если я делаю это через конфигурационный файл журнала, он работает как положено.

Я могу ошибаться но яЯ думаю, что это как-то связано со мной, не понимаяPlatformLogger который был представлен в Java 7 и который - afaik - теперь используется для всех внутренних журналов JDK. Или, может быть, я просто нене понимаю Ю.У.Л. достаточно хорошо.

Я предполагаю, что это сработает, если я сделаю:

httpLogger = PlatformLogger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
httpLogger.setLevel(Level.FINEST);

ноPlatformLogger класс находится в пакете, на который я не могу ссылаться.

Что такое ?PlatformLogger

Вот's 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 exist.

If the logging facility is not enabled, the platform loggers
will output log messages per the default logging configuration
(see below). In this implementation, it does not log the
the stack frame information issuing the log message.

When the logging facility is enabled (at startup or runtime),
the java.util.logging.Logger will be created for each platform
logger and all log messages will be forwarded to the Logger
to handle.

Logging facility is "enabled" when one of the following
conditions is met:
1) a system property "java.util.logging.config.class" or
    "java.util.logging.config.file" is set
2) java.util.logging.LogManager or java.util.logging.Logger
    is referenced that will trigger the logging initialization.

Default logging configuration:
  global logging level = INFO
  handlers = java.util.logging.ConsoleHandler
  java.util.logging.ConsoleHandler.level = INFO
  java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

Limitation:
/lib/logging.properties is the system-wide logging
configuration defined in the specification and read in the
default case to configure any java.util.logging.Logger instances.
Platform loggers will not detect if /lib/logging.properties
is modified. In other words, unless the java.util.logging API
is used at runtime or the logging system properties is set,
the platform loggers will use the default setting described above.
The platform loggers are designed for JDK developers use and
this limitation can be workaround with setting
-Djava.util.logging.config.file system property.

@since 1.7

Ответы на вопрос(2)

Ваш ответ на вопрос