2

我正在尝试配置我的第一个 GWT 记录器,到目前为止,日志消息打印到我的 JS 控制台(FF 的 Firebug):

<!-- Configure logging. -->
<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.logLevel" value="FINEST"/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<set-property name="gwt.logging.consoleHandler" value="ENABLED"/>
<set-property name="gwt.logging.developmentModeHandler" value="DISABLED" />
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
<set-property name="gwt.logging.systemHandler" value="DISABLED" />
<set-property name="gwt.logging.firebugHandler" value="DISABLED" />
<set-property name="gwt.logging.simpleRemoteHandler" value="DISABLED" />

最终,我希望非SEVERE消息转到consoleHandler,而SEVERE消息转到simpleRemoteHandler.

我怎样才能做到这一点?如何让某些日志级别转到 1 个处理程序,以及SEVERE将消息转到另一个处理程序?提前致谢!

4

1 回答 1

0

根据 gwt日志记录文档的正常方式是:

GWT logging comes with a set of Handlers already defined and (by default) attached to the Root Logger. You can disable these handlers in the .gwt.xml file as discussed above, extend them, attach them to other loggers, and so forth.

因此,基于这个想法,为您的记录器添加一个自定义处理程序,并将仅记录发送到服务器SEVERE

  // This code is almost taken from the SimpleRemoteLogHandler.java because
  // it is a final class and we cannot extend it.
  logger.addHandler(new RemoteLogHandlerBase() {

    private AsyncCallback<String> callback = new AsyncCallback<String>() {
      public void onFailure(Throwable caught) {
        wireLogger.log(Level.SEVERE, "Remote logging failed: ", caught);
      }
      public void onSuccess(String result) {
        if (result != null) {
          wireLogger.severe("Remote logging failed: " + result);
        } else {
          wireLogger.finest("Remote logging message acknowledged");
        }
      }
    };

    private RemoteLoggingServiceAsync service = (RemoteLoggingServiceAsync) GWT.create(RemoteLoggingService.class);

    @Override
    public void publish(LogRecord record) {
      if (record.getLevel() == Level.SEVERE) {
        if (isLoggable(record)) {
          service.logOnServer(record, callback);
        }
      }
    }

  });
于 2013-06-22T11:39:33.240 回答