Enhance logging
authorChristos KK Loverdos <loverdos@gmail.com>
Wed, 13 Mar 2013 13:56:55 +0000 (15:56 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Wed, 13 Mar 2013 13:56:55 +0000 (15:56 +0200)
src/gr/grnet/pithos/web/client/Pithos.java
src/gr/grnet/pithos/web/client/catalog/GetUserCatalogs.java

index 5e29ee0..f21477c 100644 (file)
@@ -341,7 +341,30 @@ public class Pithos implements EntryPoint, ResizeHandler {
             final StringBuilder sb = new StringBuilder();
             for(Object arg : args) {
                 sb.append(arg);
+                if(arg instanceof Throwable) {
+                    sb.append("\nCauses (including original):\n");
+                    final Throwable error = (Throwable) arg;
+                    Throwable cause = error;
+                    while(cause != null) {
+                        sb.append("  ");
+                        sb.append(cause.toString());
+                        sb.append("\n");
+                        cause = cause.getCause();
+                    }
+
+                    sb.append("Stack trace of original: ");
+                    sb.append(error.toString());
+                    sb.append("\n");
+                    StackTraceElement[] stackTrace = error.getStackTrace();
+                    for(StackTraceElement errorElem : stackTrace) {
+                        sb.append("  ");
+                        sb.append(errorElem.toString());
+                        sb.append("\n");
+                    }
+                }
             }
+
+
             if(sb.length() > 0) {
                 __ConsoleLog(sb.toString());
             }
index f006764..916702b 100644 (file)
@@ -42,6 +42,7 @@ import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
 import com.google.gwt.json.client.JSONValue;
+import gr.grnet.pithos.web.client.Const;
 import gr.grnet.pithos.web.client.Helpers;
 import gr.grnet.pithos.web.client.Pithos;
 
@@ -51,6 +52,7 @@ import java.util.List;
  * The request via which we obtain user catalog info.
  */
 public class GetUserCatalogs implements Scheduler.ScheduledCommand {
+    private final Pithos app;
     private final String url;
     private final String userToken;
     private final List<String> ids;
@@ -78,6 +80,8 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
     public GetUserCatalogs(Pithos app, List<String> ids, List<String> names) {
         assert app != null;
 
+        this.app = app;
+
         // FIXME: Probably use Window.Location.getHost()
         // https://server.com/v1/ --> https://server.com
         String path = app.getApiPath();
@@ -133,14 +137,16 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
     }
 
     public void onError(Request request, Throwable t) {
-        GWT.log("GetUserCatalogs", t);
+        app.LOG("GetUserCatalogs ", t);
     }
 
     @Override
     public void execute() {
         final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, getURL());
-        rb.setHeader("X-Auth-Token", userToken);
+        rb.setHeader(Const.X_AUTH_TOKEN, userToken);
         final String requestData = makeRequestData().toString();
+        app.LOG("GetUserCatalog => ", requestData);
+        app.LOG(new Exception());
 
         try {
             rb.sendRequest(requestData, new RequestCallback() {
@@ -149,12 +155,14 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
                     final int statusCode = response.getStatusCode();
 
                     if(statusCode != SuccessCode) {
+                        app.LOG("GetUserCatalog <= [", statusCode, " ", response.getStatusText(), "]");
                         GetUserCatalogs.this.onBadStatusCode(request, response);
                         return;
                     }
 
                     final String responseText = response.getText();
                     final JSONValue jsonValue = JSONParser.parseStrict(responseText);
+                    app.LOG("GetUserCatalog <= ", jsonValue.toString());
                     final JSONObject result = jsonValue.isObject();
 
                     if(result == null) {
@@ -174,7 +182,7 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
             });
         }
         catch(Exception e) {
-            GWT.log("GetUserCatalogs", e);
+            app.LOG("GetUserCatalogs. ", e);
         }
     }