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
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.