2003/12/29 03:44:16
[org.ibex.core.git] / src / org / xwt / util / Log.java
index 0554f25..c7dfddb 100644 (file)
@@ -22,14 +22,13 @@ 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) {
-        log(o, message, INFO);
-    }
+    public static synchronized void echo(Object o, Object message) { log(o, message, ECHO); }
+    public static synchronized void diag(Object o, Object message) { log(o, message, DIAGNOSTIC); }
+    public static synchronized void debug(Object o, Object message) { log(o, message, DEBUG); }
+    public static synchronized void info(Object o, Object message) { log(o, message, INFO); }
+    public static synchronized void warn(Object o, Object message) { log(o, message, WARN); }
+    public static synchronized void error(Object o, Object message) { log(o, message, ERROR); }
 
     // these two logging levels serve ONLY to change the color; semantically they are the same as DEBUG
     private static final int DIAGNOSTIC = -2;
@@ -51,6 +50,7 @@ public class Log {
     private static final int GRAY = 37;
 
     private static String color(int color, boolean bright, String s) {
+        if (!Log.color) return s;
         return
             "" + ((char)27) + "[" + (bright?1:0) + ";" + color + "m" +
             s +
@@ -61,14 +61,14 @@ public class Log {
     private static synchronized void log(Object o, Object message, int level) {
         if (firstMessage && !logDates) {
             firstMessage = false;
-            System.err.println("===========================================================================");
-            String incolor = color ? "in " +
+            System.err.println(color(GREEN, false, "==========================================================================="));
+            diag(Log.class, "Logging enabled at " + new java.util.Date());
+            if (color) diag(Log.class, "logging messages in " +
                 color(BLUE, true, "c") +
                 color(RED, true, "o") +
                 color(CYAN, true, "l") +
                 color(GREEN, true, "o") +
-                color(PURPLE, true, "r") + " " : "";
-            log(Log.class, "Logging enabled at " + new java.util.Date() + " " + incolor);
+                color(PURPLE, true, "r"));
         }
 
         String classname;
@@ -143,16 +143,16 @@ public class Log {
         if (!name.equals("")) name += " : ";
 
         if (o == null) {
-            Log.logJS(indent + name + "<null>");
+            JS.log(indent + name + "<null>");
 
         } else if (o instanceof JSArray) {
-            Log.logJS(indent + name + "<array>");
+            JS.log(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.log(indent + name + "<object>");
             JS s = (JS)o;
             Enumeration e = s.keys();
             while(e.hasMoreElements()) {
@@ -163,7 +163,7 @@ public class Log {
                                  s.get(((Integer)key)) : s.get(key.toString()));
             }
         } else {
-            Log.logJS(indent + name + o);
+            JS.log(indent + name + o);
 
         }
     }