2003/12/02 18:33:33
[org.ibex.core.git] / src / org / xwt / util / Log.java
index 71fb1ed..e75d8d8 100644 (file)
@@ -1,5 +1,6 @@
-// Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
+// Copyright 2003 Adam Megacz, see the COPYING file for licensing [LGPL]
 package org.xwt.util;
+import org.xwt.js.*;
 import java.io.*;
 import java.util.*;
 
@@ -14,9 +15,12 @@ public class Log {
     /** true iff nothing has yet been logged */
     public static boolean firstMessage = true;
 
+    /** log a message with the current JavaScript sourceName/line */
+    public static void logJS(Object o, Object message) { logJS(message); }
+    public static void logJS(Object message) { log(JS.getSourceName() + ":" + JS.getLine(), message); }
+
     /** message can be a String or a Throwable */
     public static synchronized void log(Object o, Object message) {
-
         if (firstMessage && !logDates) {
             firstMessage = false;
             System.err.println("===========================================================================");
@@ -64,4 +68,33 @@ public class Log {
         }
     }
 
+    public static void recursiveLog(String indent, String name, Object o) throws JSExn {
+        if (!name.equals("")) name += " : ";
+
+        if (o == null) {
+            Log.logJS(indent + name + "<null>");
+
+        } else if (o instanceof JSArray) {
+            Log.logJS(indent + name + "<array>");
+            JSArray na = (JSArray)o;
+            for(int i=0; i<na.length(); i++)
+                recursiveLog(indent + "  ", i + "", na.elementAt(i));
+
+        } else if (o instanceof JS) {
+            Log.logJS(indent + name + "<object>");
+            JS s = (JS)o;
+            Enumeration e = s.keys();
+            while(e.hasMoreElements()) {
+                Object key = e.nextElement();
+                if (key != null)
+                    recursiveLog(indent + "  ", key.toString(),
+                                 (key instanceof Integer) ?
+                                 s.get(((Integer)key)) : s.get(key.toString()));
+            }
+        } else {
+            Log.logJS(indent + name + o);
+
+        }
+    }
+
 }