Would like to modify WindowLogger as below:
// File client/WindowLogger
package com.allen_sauer.gwt.log.client;
import com.allen_sauer.gwt.log.client.util.DOMUtil;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.Window;
public class WindowLogger extends AbstractLogger implements
Window.ClosingHandler, CloseHandler{
private static final String CSS_LOG_MESSAGE = "log-message";
private static final String STACKTRACE_ELEMENT_PREFIX =
" at ";
private JavaScriptObject loggingWindow;
public WindowLogger() {
init(this);
Window.addWindowClosingHandler(this);
Window.addCloseHandler(this);
}
public void openLoggingWindow(){
if (loggingWindow == null){
loggingWindow = open(GWT.getModuleBaseURL() + "/logging.html",
"", "");
}
}
@Override
public boolean isSupported(){
return true;
}
public void log(int logLevel, String message){
assert false;
// Method never called since {...@link #log(int, String, Throwable)}
is
// overridden
}
@Override
public void log(int logLevel, String message, Throwable throwable){
String text = message.replaceAll("<", "<").replaceAll(">",
">");
String title = makeTitle(message, throwable);
if (throwable != null) {
while (throwable != null) {
text += throwable.getClass().getName() + ":<br><b>" +
throwable.getMessage() + "</b>";
StackTraceElement[] stackTraceElements =
throwable.getStackTrace();
if (stackTraceElements.length > 0) {
text += "<div class='log-stacktrace'>";
for (StackTraceElement element : stackTraceElements) {
text += STACKTRACE_ELEMENT_PREFIX + element + "<br>";
}
text += "</div>";
}
throwable = throwable.getCause();
if (throwable != null) {
text += "Caused by: ";
}
}
}
text = text.replaceAll("\r\n|\r|\n", "<BR>");
text = "<div class='" + CSS_LOG_MESSAGE
+ "' onmouseover='className+=\" log-message-hover\"' "
+ "onmouseout='className=className.replace(/ log-message-hover/
g,\"\")' style='color: "
+ getColor(logLevel) + "' title='" + title + "'>" + text + "</
div>";
if (loggingWindow != null){
logTextInLoggingWindow(loggingWindow, text);
}
}
public void onWindowClosing(Window.ClosingEvent event) {
if (loggingWindow != null){
closeLoggingWindow(loggingWindow);
}
}
public void onClose(CloseEvent event) {
if (loggingWindow != null){
closeLoggingWindow(loggingWindow);
}
}
private static native void init(WindowLogger me) /*-{
$wnd.windowLogger = {
onLoggingWindowClosed: function(){
[email protected]_sauer.gwt.log.client.windowlogger::onLoggingWindowClosedCallback
()();
},
abc: function(){
}
};
}-*/;
private static native JavaScriptObject open(String url, String name,
String features) /*-{
var w = $wnd.open(url, name, features);
$wnd.focus();
return w;
}-*/;
private static native void closeLoggingWindow(JavaScriptObject
loggingWindow) /*-{
loggingWindow.close();
}-*/;
/**
* Called from javascript
*/
private void onLoggingWindowClosedCallback(){
Window.alert("set loggingWindow = null");
loggingWindow = null;
}
private static native void logTextInLoggingWindow(JavaScriptObject
loggingWindow, String text) /*-{
loggingWindow.logText(text);
}-*/;
private String makeTitle(String message, Throwable throwable) {
if (throwable != null) {
if (throwable.getMessage() == null) {
message = throwable.getClass().getName();
} else {
message = throwable.getMessage().replaceAll(
throwable.getClass().getName().replaceAll("^(.+\\.).+$",
"$1"), "");
}
}
return DOMUtil.adjustTitleLineBreaks(message).replaceAll("<",
"<").replaceAll(">", ">").replaceAll(
"'", "\"");
}
private String getColor(int logLevel) {
if (logLevel == Log.LOG_LEVEL_OFF) {
return "#000"; // black
}
if (logLevel >= Log.LOG_LEVEL_FATAL) {
return "#F00"; // bright red
}
if (logLevel >= Log.LOG_LEVEL_ERROR) {
return "#C11B17"; // dark red
}
if (logLevel >= Log.LOG_LEVEL_WARN) {
return "#E56717"; // dark orange
}
if (logLevel >= Log.LOG_LEVEL_INFO) {
return "#2B60DE"; // blue
}
if (logLevel >= Log.LOG_LEVEL_DEBUG) {
return "#20b000"; // green
}
return "#F0F"; // purple
}
}
// File public/logging.html
<html>
<head>
<title>Logging Window</title>
<script language='javascript'>
function informOpener(){
window.opener.windowLogger.onLoggingWindowClosed();
}
function logText(text){
document.body.innerHTML = document.body.innerHTML + text;
document.body['scrollTop'] = 1000000;
}
</script>
</head>
<body onbeforeunload="informOpener()">
</body>
</html>
Hope this help.
Cheers
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"gwt-log" 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/gwt-log?hl=en
-~----------~----~----~----~------~----~------~--~---