JDK: how to enable PlatformLogger programmatically

前端 未结 2 1053
没有蜡笔的小新
没有蜡笔的小新 2021-02-14 09:34

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         


        
相关标签:
2条回答
  • 2021-02-14 10:19

    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

    0 讨论(0)
  • 2021-02-14 10:23

    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.

    0 讨论(0)
提交回复
热议问题