First you need to supply a custom formatter. Look at
com.google.gwt.logging.client.TextLogFormatter for a simple example or, this
is an example of a formatter that format log message in a single line:
public class CustomFormatter extends FormatterImpl {
private boolean showStackTraces;
private final DateTimeFormat dtFormat =
DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
public CustomFormatter(boolean showStackTraces) {
this.showStackTraces = showStackTraces;
}
@Override
public String format(LogRecord event) {
StringBuilder message = new StringBuilder();
message.append(getRecordInfo(event, " "));
message.append(event.getMessage());
if (showStackTraces) {
message.append(getStackTraceAsString(event.getThrown(), "\n", "\t"));
}
return message.toString();
}
@Override
protected String getRecordInfo(LogRecord event, String newline) {
Date date = new Date(event.getMillis());
StringBuilder s = new StringBuilder();
s.append(dtFormat.format(date));
s.append(" "); // comment this line to get rid of classpath name
s.append(event.getLoggerName()); // comment this line to get rid of
classpath name
s.append(newline);
s.append(event.getLevel().getName());
s.append(": ");
return s.toString();
}
}
Then all you have to do is associate your custom formatter with log
handlers:
public class MyGwtApp implements EntryPoint {
private static final Logger log =
Logger.getLogger(MyGwtApp.class.getName());
// initialize logger with custom formatter
static {
Handler handlers[] = Logger.getLogger("").getHandlers();
for (Handler handler : handlers) {
handler.setFormatter(new CustomFormatter(false));
}
}
....
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.