Patch for class com.google.gwt.logging.client.ConsoleLogHandler - correcting log verbose

28 views
Skip to first unread message

larzeni

unread,
Jul 3, 2025, 5:34:15 AMJul 3
to GWT Contributors
Dear Sir,
I beg your pardon since I'm not yet acquainted with the procedures for patching gwt, so I post here my proposal, hoping that someone with enough rights can place it in the next release.

The file:

user/src/com/google/gwt/logging/client/ConsoleLogHandler.java
has a minor flaws in the console logging.

Most browser now have a 4 levels filter (ERRORS, WARNING, INFO and VERBOSE),
but the ConsoleLogHandler.publish() method logs level lower than info using the console.log method()

// ---------- CODE BEGIN ---------------------
  @Override
  public void publish(LogRecord record) {
    if (!isSupported() || !isLoggable(record)) {
      return;
    }
    String msg = getFormatter().format(record);
    int val = record.getLevel().intValue();
    if (val >= Level.SEVERE.intValue()) {
      error(msg);
    } else if (val >= Level.WARNING.intValue()) {
      warn(msg);
    } else if (val >= Level.INFO.intValue()) {
      info(msg);
    } else {
      log(msg);
    }
  }

  private native boolean isSupported() /*-{
    return !!window.console;
  }-*/;

  private native void error(String message) /*-{
    window.console.error(message);
  }-*/;

  private native void warn(String message) /*-{
    window.console.warn(message);
  }-*/;

  private native void info(String message) /*-{
    window.console.info(message);
  }-*/;

  private native void log(String message) /*-{
    window.console.log(message);
  }-*/;

// ---------- CODE END ---------------------

This is a mistake, since the console.log() and the console.info() methods are both logging at INFO level. This way the "verbose" filter of the console is unuseful.

The solution is to replace the console.log() method with the console.debug() method, that is:

  private native void log(String message) /*-{
    window.console.debug(message);
  }-*/;

(May be better also to rename the method from "  private native void log(String message)" to "  private native void verbose(String message)" to make it more explicit.

Please let me know if I my proposal can be accepted or I need to do something else.

Thanks a lot,
Luca





Jens

unread,
Jul 3, 2025, 7:32:12 AMJul 3
to GWT Contributors
Should be fine to use console.debug() for anything more verbose than INFO.

-- J.

larzeni

unread,
Jul 3, 2025, 8:32:07 AMJul 3
to GWT Contributors
Thanks for you approval!

I submitted the change using github.

Regards,
Luca

Reply all
Reply to author
Forward
0 new messages