GWT logging setup

后端 未结 3 700
挽巷
挽巷 2020-12-28 22:55

I\'m using GWT 2.1 java.util.logging emulation to log client side messages. According to the doc, two Formatters are provided (TextFormatter and HTMLFormatter) which are app

3条回答
  •  鱼传尺愫
    2020-12-28 23:10

    Here is a simple example of adding a Log handler to the Root logger. The logger uses the HTMLLogFormatter and puts the message in a HTML widget.

    HTML html = new HTML();
    // add the html widget somewhere in your code.
    Logger.getLogger("").addHandler(new Handler() {
      {
        // set the formatter, in this case HtmlLogFormatter
        setFormatter(new HtmlLogFormatter(true));
        setLevel(Level.ALL);
      }
    
      @Override
      public void publish(LogRecord record) {
        if (!isLoggable(record)) {
          Formatter formatter = getFormatter();
          String msg = formatter.format(record);
    
          html.setHTML(msg);
        }
      }
    });
    

    Also have a look at HasWidgetsLogHandler, which basically does what the handler in the example above does.

提交回复
热议问题