Revision: 8834
Author: [email protected]
Date: Tue Sep 21 13:12:02 2010
Log: Get strong permutation from headers rather than serialized log record

Review at http://gwt-code-reviews.appspot.com/880802

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8834

Added:
 /trunk/user/src/com/google/gwt/logging/client/RemoteLogHandlerBase.java
 /trunk/user/src/com/google/gwt/logging/server/RemoteLoggingServiceUtil.java
Modified:
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java /trunk/samples/logexample/src/com/google/gwt/sample/logexample/LogExample.gwt.xml /trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.java
 /trunk/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java
 /trunk/user/src/com/google/gwt/logging/client/SimpleRemoteLogHandler.java
 /trunk/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java
 /trunk/user/src/com/google/gwt/logging/server/RemoteLoggingServiceImpl.java
 /trunk/user/src/com/google/gwt/logging/server/StackTraceDeobfuscator.java
 /trunk/user/src/com/google/gwt/logging/shared/SerializableLogRecord.java
/trunk/user/src/com/google/gwt/requestfactory/client/RequestFactoryLogHandler.java
 /trunk/user/src/com/google/gwt/requestfactory/server/Logging.java
 /trunk/user/src/com/google/gwt/requestfactory/shared/LoggingRequest.java

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/logging/client/RemoteLogHandlerBase.java Tue Sep 21 13:12:02 2010
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.gwt.logging.client;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+/**
+ * Base class for Logging handlers that send records to the server.
+ */
+public abstract class RemoteLogHandlerBase extends Handler {
+  protected static final String WIRE_LOGGER_NAME = "WireActivityLogger";
+
+  // A separate logger for wire activity, which does not get logged
+  // by the remote log handler, so we avoid infinite loops.
+  protected static Logger wireLogger = Logger.getLogger(WIRE_LOGGER_NAME);
+
+  private boolean closed = false;
+
+  private List<String> excludedLoggerNames;
+  protected RemoteLogHandlerBase() {
+    excludedLoggerNames = new ArrayList<String>();
+    excludedLoggerNames.add(WIRE_LOGGER_NAME);
+  }
+
+  protected RemoteLogHandlerBase(List<String> excludedLoggerNames) {
+    this.excludedLoggerNames = excludedLoggerNames;
+    this.excludedLoggerNames.add(WIRE_LOGGER_NAME);
+  }
+
+  @Override
+  public void close() {
+    closed = true;
+  }
+
+  @Override
+  public void flush() {
+    // No action needed
+  }
+
+  @Override
+  public boolean isLoggable(LogRecord record) {
+    return (!closed &&
+        !excludedLoggerNames.equals(record.getLoggerName()));
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/logging/server/RemoteLoggingServiceUtil.java Tue Sep 21 13:12:02 2010
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.gwt.logging.server;
+
+import com.google.gwt.logging.shared.SerializableLogRecord;
+
+import org.json.JSONException;
+
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+/**
+ * Utilities for classes that accept Remote Logging requests
+ */
+public class RemoteLoggingServiceUtil {
+  /**
+   * Exceptions that occur during remote logging
+   */
+  public static class RemoteLoggingException extends Exception {
+    public RemoteLoggingException(String message) {
+      super(message);
+    }
+
+    public RemoteLoggingException(String message, Throwable t) {
+      super(message, t);
+    }
+  }
+
+  /**
+   * Logs a message on the server
+   * @param slr LogRecord to be logged
+ * @param strongName Permutation name (used for deobfuscation and may be null,
+   *        which will only cause deobfuscation to fail)
+ * @param deobfuscator used for deobfuscation. May be null, which will only
+   *        cause deobfuscation to fail.
+ * @param loggerNameOverride logger name for messages logged on server. May be
+   *        null, in which case, messages will be logged to a logger
+   *        corresponding to the client side logger which triggered them.
+   *
+ * @return Empty string when successful, or an error string in case of failure.
+   */
+ public static void logOnServer(SerializableLogRecord slr, String strongName, + StackTraceDeobfuscator deobfuscator, String loggerNameOverride) throws
+      RemoteLoggingException {
+    if (deobfuscator != null) {
+      slr = deobfuscator.deobfuscateLogRecord(slr, strongName);
+    }
+    LogRecord lr = slr.getLogRecord();
+    if (lr == null) {
+ // If he SerializableLogRecord is corrupt somehow and conversion fails
+      // TODO(unnurg): Set the cause here correctly if we don't remove
+      // SerializableLogRecord before 2.1 release.
+      throw new RemoteLoggingException(
+          "Failed to convert SerializableLogRecord to LogRecord");
+    }
+    String loggerName = loggerNameOverride == null ? lr.getLoggerName() :
+      loggerNameOverride;
+    Logger logger = Logger.getLogger(loggerName);
+    logger.log(lr);
+  }
+
+  public static void logOnServer(String serializedLogRecordJson,
+      String strongName, StackTraceDeobfuscator deobfuscator,
+      String loggerNameOverride) throws RemoteLoggingException {
+    SerializableLogRecord slr;
+    try {
+      slr = JsonLogRecordServerUtil.serializableLogRecordFromJson(
+          serializedLogRecordJson);
+      logOnServer(slr, strongName, deobfuscator, loggerNameOverride);
+    } catch (JSONException e) {
+      throw new RemoteLoggingException("Failed to deserialize JSON", e);
+    }
+  }
+}
=======================================
--- /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java Sun Sep 19 10:42:32 2010 +++ /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java Tue Sep 21 13:12:02 2010
@@ -32,6 +32,7 @@
 import com.google.gwt.user.client.ui.RootLayoutPanel;
 import com.google.gwt.user.client.ui.Widget;

+import java.util.ArrayList;
 import java.util.logging.Level;
 import java.util.logging.Logger;

@@ -76,7 +77,7 @@
     };
     Logger.getLogger("").addHandler(
         new RequestFactoryLogHandler(provider, Level.WARNING,
-            "WireActivityLogger", GWT.getPermutationStrongName()));
+            new ArrayList<String>()));
     FavoritesManager manager = new FavoritesManager(requests);
     PersonEditorWorkflow.register(eventBus, requests, manager);

=======================================
--- /trunk/samples/logexample/src/com/google/gwt/sample/logexample/LogExample.gwt.xml Fri Jun 18 13:13:05 2010 +++ /trunk/samples/logexample/src/com/google/gwt/sample/logexample/LogExample.gwt.xml Tue Sep 21 13:12:02 2010
@@ -23,6 +23,9 @@

   <!-- Disable the firebug handler as an example -->
   <set-property name="gwt.logging.firebugHandler" value="DISABLED" />
+
+  <!-- Enable the simple remote handler -->
+  <set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />

   <!-- Try uncommenting some of the following to configure logging further
   <set-property name="gwt.logging.enabled" value="FALSE"/>
=======================================
--- /trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.java Mon Sep 13 08:42:16 2010 +++ /trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.java Tue Sep 21 13:12:02 2010
@@ -66,12 +66,8 @@

   @UiHandler("exceptionButton")
   void handleExceptionClick(ClickEvent e) {
-    try {
-      Level n = null;
-      n.getName();
-    } catch (NullPointerException ex) {
-      logger.log(Level.SEVERE, "Null Exception Hit", ex);
-    }
+      logger.log(Level.SEVERE, "Fake Null Exception Hit",
+          new NullPointerException());
   }

   @UiHandler("logButton")
=======================================
--- /trunk/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java Wed Sep 15 17:53:58 2010 +++ /trunk/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java Tue Sep 21 13:12:02 2010
@@ -49,7 +49,6 @@
     obj.put("level", getJsonString(slr.getLevel()));
     obj.put("loggerName", getJsonString(slr.getLoggerName()));
     obj.put("msg", getJsonString(slr.getMsg()));
-    obj.put("strongName", getJsonString(slr.getStrongName()));
     if (slr.getTimestamp() != null) {
       obj.put("timestamp", new JSONString(slr.getTimestamp().toString()));
     }
=======================================
--- /trunk/user/src/com/google/gwt/logging/client/SimpleRemoteLogHandler.java Wed Sep 15 17:53:58 2010 +++ /trunk/user/src/com/google/gwt/logging/client/SimpleRemoteLogHandler.java Tue Sep 21 13:12:02 2010
@@ -22,59 +22,39 @@
 import com.google.gwt.logging.shared.SerializableLogRecord;
 import com.google.gwt.user.client.rpc.AsyncCallback;

-import java.util.logging.Handler;
 import java.util.logging.LogRecord;
-import java.util.logging.Logger;

 /**
* A very simple handler which sends messages to the server via GWT RPC to be - * logged. Note that this logger should not be used in production. It does not
- * do any intelligent batching of RPC's, nor does it disable when the RPC
- * calls fail repeatedly.
+ * logged. Note that this logger does not do any intelligent batching of RPC's,
+ * nor does it disable when the RPC calls fail repeatedly.
  */
-public final class SimpleRemoteLogHandler extends Handler {
-  private static Logger logger =
-    Logger.getLogger(SimpleRemoteLogHandler.class.getName());
-
+public final class SimpleRemoteLogHandler extends RemoteLogHandlerBase {
   class DefaultCallback implements AsyncCallback<String> {
     public void onFailure(Throwable caught) {
-      logger.severe("Remote logging failed: " + caught.toString());
+      wireLogger.severe("Remote logging failed: " + caught.toString());
     }
     public void onSuccess(String result) {
-      if (result.length() > 0) {
-        logger.severe("Remote logging failed: " + result);
+      if (result != null) {
+        wireLogger.severe("Remote logging failed: " + result);
       } else {
-        logger.finest("Remote logging message acknowledged");
+        wireLogger.finest("Remote logging message acknowledged");
       }
     }
   }

-  private RemoteLoggingServiceAsync service;
   private AsyncCallback<String> callback;
+  private RemoteLoggingServiceAsync service;

   public SimpleRemoteLogHandler() {
service = (RemoteLoggingServiceAsync) GWT.create(RemoteLoggingService.class);
     this.callback = new DefaultCallback();
   }

-  @Override
-  public void close() {
-    // No action needed
-  }
-
-  @Override
-  public void flush() {
-    // No action needed
-  }
-
   @Override
   public void publish(LogRecord record) {
-    if (record.getLoggerName().equals(logger.getName())) {
-      // We don't want to propagate our own messages to the server since it
-      // would lead to an infinite loop.
-      return;
-    }
-    service.logOnServer(new SerializableLogRecord(
-        record, GWT.getPermutationStrongName()), callback);
+    if (isLoggable(record)) {
+      service.logOnServer(new SerializableLogRecord(record), callback);
+    }
   }
 }
=======================================
--- /trunk/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java Wed Sep 15 17:53:58 2010 +++ /trunk/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java Tue Sep 21 13:12:02 2010
@@ -34,56 +34,46 @@
  */
 public class JsonLogRecordServerUtil {
   public static SerializableLogRecord serializableLogRecordFromJson(
-      String jsonString) {
-    try {
-      JSONObject slr = new JSONObject(jsonString);
-      String level = slr.getString("level");
-      String loggerName = slr.getString("loggerName");
-      String msg = slr.getString("msg");
-      String strongName = slr.getString("strongName");
-      long timestamp = Long.parseLong(slr.getString("timestamp"));
-      SerializableThrowable thrown =
-        serializableThrowableFromJson(slr.getString("thrown"));
-      return new SerializableLogRecord(level, loggerName, msg, thrown,
-          timestamp, strongName);
-    } catch (JSONException e) {
-    }
-    return null;
+      String jsonString) throws JSONException {
+    JSONObject slr = new JSONObject(jsonString);
+    String level = slr.getString("level");
+    String loggerName = slr.getString("loggerName");
+    String msg = slr.getString("msg");
+    long timestamp = Long.parseLong(slr.getString("timestamp"));
+    SerializableThrowable thrown =
+      serializableThrowableFromJson(slr.getString("thrown"));
+    return new SerializableLogRecord(level, loggerName, msg, thrown,
+        timestamp);
   }

   private static StackTraceElement serializableStackTraceElementFromJson(
-      String jsonString) {
-    try {
-      JSONObject ste = new JSONObject(jsonString);
-      String className = ste.getString("className");
-      String fileName = ste.getString("fileName");
-      String methodName = ste.getString("methodName");
-      int lineNumber = Integer.parseInt(ste.getString("lineNumber"));
-      return new StackTraceElement(className, methodName, fileName,
-          lineNumber);
-    } catch (JSONException e) {
-    }
-    return null;
+      String jsonString) throws JSONException {
+    JSONObject ste = new JSONObject(jsonString);
+    String className = ste.getString("className");
+    String fileName = ste.getString("fileName");
+    String methodName = ste.getString("methodName");
+    int lineNumber = Integer.parseInt(ste.getString("lineNumber"));
+    return new StackTraceElement(className, methodName, fileName,
+        lineNumber);
   }

   private static SerializableThrowable serializableThrowableFromJson(
-      String jsonString) {
-    try {
-      JSONObject t = new JSONObject(jsonString);
-      String message = t.getString("message");
-      SerializableThrowable cause =
-        serializableThrowableFromJson(t.getString("cause"));
-      StackTraceElement[] stackTrace = null;
-      JSONArray st = t.getJSONArray("stackTrace");
-      if (st.length() > 0) {
-        stackTrace = new StackTraceElement[st.length()];
-        for (int i = 0; i < st.length(); i++) {
- stackTrace[i] = serializableStackTraceElementFromJson(st.getString(i));
-        }
-      }
-      return new SerializableThrowable(message, cause, stackTrace);
-    } catch (JSONException e) {
-    }
-    return null;
+      String jsonString) throws JSONException {
+    if (jsonString.equals("{}")) {
+      return null;
+    }
+    JSONObject t = new JSONObject(jsonString);
+    String message = t.getString("message");
+    SerializableThrowable cause =
+      serializableThrowableFromJson(t.getString("cause"));
+    StackTraceElement[] stackTrace = null;
+    JSONArray st = t.getJSONArray("stackTrace");
+    if (st.length() > 0) {
+      stackTrace = new StackTraceElement[st.length()];
+      for (int i = 0; i < st.length(); i++) {
+ stackTrace[i] = serializableStackTraceElementFromJson(st.getString(i));
+      }
+    }
+    return new SerializableThrowable(message, cause, stackTrace);
   }
 }
=======================================
--- /trunk/user/src/com/google/gwt/logging/server/RemoteLoggingServiceImpl.java Mon Jun 28 12:35:42 2010 +++ /trunk/user/src/com/google/gwt/logging/server/RemoteLoggingServiceImpl.java Tue Sep 21 13:12:02 2010
@@ -16,10 +16,12 @@

 package com.google.gwt.logging.server;

+import com.google.gwt.logging.server.RemoteLoggingServiceUtil.RemoteLoggingException;
 import com.google.gwt.logging.shared.RemoteLoggingService;
 import com.google.gwt.logging.shared.SerializableLogRecord;
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;

+import java.util.logging.Level;
 import java.util.logging.Logger;

 /**
@@ -27,21 +29,52 @@
  */
public class RemoteLoggingServiceImpl extends RemoteServiceServlet implements
     RemoteLoggingService {
-  private static Logger logger = Logger.getLogger("gwt.remote");
-
-  public final String logOnServer(SerializableLogRecord record) {
+  // No deobfuscator by default
+  private static StackTraceDeobfuscator deobfuscator = null;
+
+  private static Logger logger =
+    Logger.getLogger(RemoteServiceServlet.class.getName());
+
+  private static String loggerNameOverride = null;
+
+  /**
+ * Logs a Log Record which has been serialized using GWT RPC on the server.
+   * Returns either an error message, or null if logging is successful.
+   */
+  public final String logOnServer(SerializableLogRecord slr) {
+    String strongName = getPermutationStrongName();
     try {
-      logger.log(record.getLogRecord());
-    } catch (RuntimeException e) {
-      String exceptionString = e.toString();
- String failureMessage = "Failed to log message due to " + exceptionString;
-      System.err.println(failureMessage);
-      e.printStackTrace();
-
-      // Return the exception description so that the client code can
-      // print or log it if it wants.
-      return e.toString();
-    }
-    return "";
-  }
-}
+      RemoteLoggingServiceUtil.logOnServer(
+          slr, strongName, deobfuscator, loggerNameOverride);
+    } catch (RemoteLoggingException e) {
+      logger.log(Level.SEVERE, "Remote logging failed", e);
+      return "Remote logging failed";
+    }
+    return null;
+  }
+
+  /**
+   * By default, messages are logged to a logger that has the same name as
+ * the logger that created them on the client. If you want to log all messages + * from the client to a logger with another name, you can set the override
+   * using this method.
+   */
+  public void setLoggerNameOverride(String override) {
+    loggerNameOverride = override;
+  }
+
+  /**
+   * By default, this service does not do any deobfuscation. In order to do
+   * server side deobfuscation, you must copy the symbolMaps files to a
+ * directory visible to the server and set the directory using this method.
+   * @param symbolMapsDir
+   */
+  public void setSymbolMapsDirectory(String symbolMapsDir) {
+    if (deobfuscator == null) {
+      deobfuscator = new StackTraceDeobfuscator(symbolMapsDir);
+    } else {
+      deobfuscator.setSymbolMapsDirectory(symbolMapsDir);
+    }
+  }
+
+}
=======================================
--- /trunk/user/src/com/google/gwt/logging/server/StackTraceDeobfuscator.java Wed Sep 15 17:53:58 2010 +++ /trunk/user/src/com/google/gwt/logging/server/StackTraceDeobfuscator.java Tue Sep 21 13:12:02 2010
@@ -48,7 +48,7 @@
   private static Pattern JsniRefPattern =
     Pattern.compile("@?([^:]+)::([^(]+)(\\((.*)\\))?");

-  private String symbolMapsDirectory = "";
+  private String symbolMapsDirectory;

   private Map<String, SymbolMap> symbolMaps =
     new HashMap<String, SymbolMap>();
@@ -58,15 +58,22 @@
   }

   public SerializableLogRecord deobfuscateLogRecord(
-      SerializableLogRecord slr) {
-    if (slr.getThrown() != null) {
- slr.setThrown(deobfuscateThrowable(slr.getThrown(), slr.getStrongName()));
+      SerializableLogRecord slr, String strongName) {
+    if (slr.getThrown() != null && strongName != null) {
+      slr.setThrown(deobfuscateThrowable(slr.getThrown(), strongName));
     }
     return slr;
   }

   public void setSymbolMapsDirectory(String dir) {
-    symbolMapsDirectory = dir;
+    // Switching the directory should clear the symbolMaps variable (which
+ // is read in lazily), but causing the symbolMaps variable to be re-read + // is somewhat expensive, so we only want to do this if the directory is
+    // actually different.
+    if (!dir.equals(symbolMapsDirectory)) {
+      symbolMapsDirectory = dir;
+      symbolMaps = new HashMap<String, SymbolMap>();
+    }
   }

   private StackTraceElement[] deobfuscateStackTrace(
=======================================
--- /trunk/user/src/com/google/gwt/logging/shared/SerializableLogRecord.java Wed Sep 15 17:53:58 2010 +++ /trunk/user/src/com/google/gwt/logging/shared/SerializableLogRecord.java Tue Sep 21 13:12:02 2010
@@ -33,18 +33,13 @@
   private String level;
   private String loggerName = "";
   private String msg;
- // TODO(unnurg): if/when we ever start passing the strong name in all headers
-  // and we're able to access request headers in the Vega logging handler
-  // remove this strongName variable from here.
-  private String strongName = "";
   private SerializableThrowable thrown = null;
   private long timestamp;

   /**
    * Create a new SerializableLogRecord from a LogRecord.
    */
-  public SerializableLogRecord(LogRecord lr, String strongName) {
-    this.strongName = strongName;
+  public SerializableLogRecord(LogRecord lr) {
     level = lr.getLevel().toString();
     loggerName = lr.getLoggerName();
     msg = lr.getMessage();
@@ -55,13 +50,12 @@
   }

   public SerializableLogRecord(String level, String loggerName, String msg,
-      SerializableThrowable thrown, long timestamp, String strongName) {
+      SerializableThrowable thrown, long timestamp) {
     this.level = level;
     this.loggerName = loggerName;
     this.msg = msg;
     this.timestamp = timestamp;
     this.thrown = thrown;
-    this.strongName = strongName;
   }

   protected SerializableLogRecord() {
@@ -92,10 +86,6 @@
   public String getMsg() {
     return msg;
   }
-
-  public String getStrongName() {
-    return strongName;
-  }

   public SerializableThrowable getThrown() {
     return thrown;
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/RequestFactoryLogHandler.java Sat Sep 18 09:13:37 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/RequestFactoryLogHandler.java Tue Sep 21 13:12:02 2010
@@ -17,19 +17,19 @@
 package com.google.gwt.requestfactory.client;

 import com.google.gwt.logging.client.JsonLogRecordClientUtil;
+import com.google.gwt.logging.client.RemoteLogHandlerBase;
 import com.google.gwt.logging.shared.SerializableLogRecord;
 import com.google.gwt.requestfactory.shared.LoggingRequest;
 import com.google.gwt.requestfactory.shared.Receiver;

-import java.util.logging.Handler;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
-import java.util.logging.Logger;

 /**
* A Handler that does remote logging for applications using RequestFactory.
  */
-public class RequestFactoryLogHandler extends Handler {
+public class RequestFactoryLogHandler extends RemoteLogHandlerBase {

   /**
    * Provides a logging request.
@@ -42,70 +42,45 @@
     @Override
     public void onSuccess(Long response) {
       if (response > 0) {
-        logger.finest("Remote logging successful");
+        wireLogger.finest("Remote logging successful");
       } else {
-        logger.finest("Remote logging failed");
+        wireLogger.severe("Remote logging failed");
       }
     }
   }

-  private static Logger logger =
-    Logger.getLogger(RequestFactoryLogHandler.class.getName());
-
-  // A separate logger for wire activity, which does not get logged
-  // by the remote log handler, so we avoid infinite loops.
- private static Logger wireLogger = Logger.getLogger("WireActivityLogger");
-
-  private boolean closed;
   private LoggingRequestProvider requestProvider;
-  private String ignoredLoggerSubstring;
-  private String strongName;

   /**
    * Since records from this handler go accross the wire, it should only be
* used for important messages, and it's Level will often be higher than the - * Level being used app-wide. This handler also takes a string which it will + * Level being used app-wide. This handler also takes string which it will * use to exclude the messages from some loggers. This usually includes the
    * name of the logger(s) which will be used to log acknowledgements of
* activity going accross the wire. If we did not exclude these loggers, an
    * infinite loop would occur.
    */
   public RequestFactoryLogHandler(LoggingRequestProvider requestProvider,
-      Level level, String ignoredLoggerSubstring, String strongName) {
+      Level level, List<String> ignoredLoggerNames) {
+    super(ignoredLoggerNames);
     this.requestProvider = requestProvider;
-    this.ignoredLoggerSubstring = ignoredLoggerSubstring;
-    this.strongName = strongName;
-    closed = false;
     setLevel(level);
   }
-
-  @Override
-  public void close() {
-    closed = true;
-  }
-
-  @Override
-  public void flush() {
-    // Do nothing
-  }

   @Override
   public void publish(LogRecord record) {
-    if (closed || !isLoggable(record)) {
+    if (!isLoggable(record)) {
       return;
     }
-    if (record.getLoggerName().contains(ignoredLoggerSubstring)) {
-      return;
-    }
     SerializableLogRecord slr =
-      new SerializableLogRecord(record, strongName);
+      new SerializableLogRecord(record);
     String json = JsonLogRecordClientUtil.serializableLogRecordAsJson(slr);
     requestProvider.getLoggingRequest().logMessage(json).fire(
-        new Receiver<Boolean>() {
+        new Receiver<String>() {
           @Override
-          public void onSuccess(Boolean response) {
-            if (!response) {
-              wireLogger.severe("Remote Logging failed to parse JSON");
+          public void onSuccess(String response) {
+            if (!response.isEmpty()) {
+ wireLogger.severe("Remote Logging failed on server: " + response);
             }
           }
         });
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/Logging.java Sun Sep 19 16:42:30 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/Logging.java Tue Sep 21 13:12:02 2010
@@ -16,11 +16,12 @@

 package com.google.gwt.requestfactory.server;

-import com.google.gwt.logging.server.JsonLogRecordServerUtil;
+import com.google.gwt.logging.server.RemoteLoggingServiceUtil;
+import com.google.gwt.logging.server.RemoteLoggingServiceUtil.RemoteLoggingException;
 import com.google.gwt.logging.server.StackTraceDeobfuscator;
-import com.google.gwt.logging.shared.SerializableLogRecord;
-
-import java.util.logging.LogRecord;
+import com.google.gwt.user.client.rpc.RpcRequestBuilder;
+
+import java.util.logging.Level;
 import java.util.logging.Logger;

 /**
@@ -35,18 +36,24 @@
   private static StackTraceDeobfuscator deobfuscator =
     new StackTraceDeobfuscator("");

-  public static Boolean logMessage(String serializedLogRecordString) {
-    SerializableLogRecord slr =
-      JsonLogRecordServerUtil.serializableLogRecordFromJson(
-          serializedLogRecordString);
-    slr = deobfuscator.deobfuscateLogRecord(slr);
-    LogRecord lr = slr.getLogRecord();
-    if (lr == null) {
-      return false;
-    }
-    Logger logger = Logger.getLogger(lr.getLoggerName());
-    logger.log(lr);
-    return true;
+  private static Logger logger = Logger.getLogger(Logging.class.getName());
+
+  public static String logMessage(String serializedLogRecordJson) {
+ // if the header does not exist, we pass null, which is handled gracefully
+    // by the deobfuscation code.
+    String strongName =
+      RequestFactoryServlet.getThreadLocalRequest().getHeader(
+          RpcRequestBuilder.STRONG_NAME_HEADER);
+    try {
+      RemoteLoggingServiceUtil.logOnServer(serializedLogRecordJson,
+          strongName, deobfuscator, null);
+    } catch (RemoteLoggingException e) {
+ // TODO(unnurg): Change this to use server failure reporting when it is
+      // submitted.
+      logger.log(Level.SEVERE, "Remote logging failed", e);
+      return "Remote logging failed";
+    }
+    return "";
   }

   /**
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/LoggingRequest.java Wed Sep 15 17:53:58 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/LoggingRequest.java Tue Sep 21 13:12:02 2010
@@ -27,6 +27,10 @@

   // TODO(unnurg): Pass a SerializableLogRecord here rather than it's
   // serialized string.
-  RequestObject<Boolean> logMessage(String serializedLogRecordString);
+  /**
+ * Log a message on the server. Will return empty string if there is no error
+   * or an error message if there is a problem.
+   */
+  RequestObject<String> logMessage(String serializedLogRecordString);

 }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to