I need to enable logging for some JDK7 internal class programmatically.
This is what I do in the initialization of my application:
httpLogger = Logger.ge
You have to read it first what is saying.
the PlatformLogger API can be used if the logging module does not exist
Well the if you want to use that API you than use following import statement.
import sun.util.logging.PlatformLogger;
Above is the complete reference to your destination.
For Further Reference Visit BUG Tracking of Java
My solution that appears at the beginning of a small custom widget demo program:
// Log all focus messages.
final Logger rootLogger = Logger.getLogger("");
rootLogger.setLevel(Level.ALL);
final ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);
// Because there are a lot of focus messages, make them
// a little easier to read by logging only the message.
consoleHandler.setFormatter(new Formatter() {
@Override
public String format(LogRecord record) {
return "FOCUS: " + record.getMessage() + '\n';
}
});
final Logger logger = Logger.getLogger("java.awt.focus.Component");
logger.setLevel(Level.ALL);
logger.setUseParentHandlers(false);
logger.addHandler(consoleHandler);
It's unclear to me why I needed to get then set the rootLogger level to ALL, but that's what I needed.