At first glance, you will not be able to configure the logging level for sun.net.www.protocol.http.HttpURLConnection
using Log4j, no matter if you use properties
or xml
configuration files.
As you can see in the source code of the HttpURLConnection
class, its logging is based in PlatformLogger
, which in turn uses java.util.logging
.
The PlatformLogger
javadoc describes how it should be configured:
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:
- a system property "java.util.logging.config.class" or
"java.util.logging.config.file" is set
- 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
Basically, you need to configure the system property java.util.logging.config.file
pointing to an appropriate properties
file with the required properties:
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=INFO
sun.net.www.protocol.http.HttpURLConnection.level=ALL
Please, consider review this related SO question, it provides different examples and further information about how to do it.
As suggested in that question, you can use the system property javax.net.debug
as well:
-Djavax.net.debug=all
If you want to integrate Log4j and java.util.logging
, you can try using libraries like SLF4J and the corresponding bridges. This related SO question provides more information.