Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT logging setup

Tags:

logging

gwt

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 appropriate to client side logging.

Can anyone provide an example on how to setup a formatter and attach it to a handler in GWT?

Thanks

like image 822
Javier Ferrero Avatar asked Jan 26 '11 12:01

Javier Ferrero


2 Answers

See the GWT documentation for logging here. It really depends on where you want your logging to appear, but if you only care about logging in Dev mode then you only need the SystemLogHandler and the DevelopmentModeLogHandler. The ConsoleLogHandler and FirebugLogHandler are used for web mode logging to chrome, firebug and firebug lite. The PopupLogHandler and HasWidgetsLogHandler add the log messages to some sort of UI element. All of the above should be capable of being enabled/disabled in the .gwt.xml except the HasWidgetsLogHandler which requires an associated widget container. This should be possible by adding the following:

<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.logLevel" value="SEVERE"/> # To change the default logLevel
<set-property name="gwt.logging.enabled" value="FALSE"/> # To disable logging
<set-property name="gwt.logging.consoleHandler" value="DISABLED"/>  # To disable a default Handler
<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="ENABLED" />
etc...
like image 191
LINEMAN78 Avatar answered Sep 28 '22 04:09

LINEMAN78


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.

like image 26
Hilbrand Bouwkamp Avatar answered Sep 28 '22 05:09

Hilbrand Bouwkamp