X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Futil%2FLog.java;h=03c5a521aa991eab52ebe7e3dd43f009ca45fd20;hb=30aa8aa58f30808651a02e089c84998d6e054cbb;hp=aa24171b42583d7bd44bbcfb1bd42a1af4076c7a;hpb=e497cb520e0a5ef7de3db0f515af1822afb6a7a6;p=org.ibex.core.git diff --git a/src/org/xwt/util/Log.java b/src/org/xwt/util/Log.java index aa24171..03c5a52 100644 --- a/src/org/xwt/util/Log.java +++ b/src/org/xwt/util/Log.java @@ -14,7 +14,7 @@ import java.util.*; public class Log { public static boolean on = true; - public static boolean color = true; + public static boolean color = false; public static boolean verbose = false; public static boolean logDates = false; public static Date lastDate = null; @@ -22,12 +22,9 @@ 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 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); } @@ -51,26 +48,27 @@ public class Log { private static final int PURPLE = 35; private static final int BROWN = 33; private static final int GRAY = 37; - - private static String color(int color, boolean bright, String s) { + + private static String colorize(int color, boolean bright, String s) { + if (!Log.color) return s; return - "" + ((char)27) + "[" + (bright?1:0) + ";" + color + "m" + + "\033[40;" + (bright?"1;":"") + color + "m" + s + - ((char)27) + "[0m"; + "\033[0m"; } private static String lastClassName = null; private static synchronized void log(Object o, Object message, int level) { if (firstMessage && !logDates) { firstMessage = false; - System.err.println("==========================================================================="); - String incolor = color ? "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); + System.err.println(colorize(GREEN, false, "===========================================================================")); + diag(Log.class, "Logging enabled at " + new java.util.Date()); + if (color) diag(Log.class, "logging messages in " + + colorize(BLUE, true, "c") + + colorize(RED, true, "o") + + colorize(CYAN, true, "l") + + colorize(GREEN, true, "o") + + colorize(PURPLE, true, "r")); } String classname; @@ -85,14 +83,15 @@ public class Log { if (classname.length() > (logDates ? 14 : 20)) classname = classname.substring(0, (logDates ? 14 : 20)); while (classname.length() < (logDates ? 14 : 20)) classname = " " + classname; classname = classname + (classname.trim().length() == 0 ? " " : ": "); - classname = color(GRAY, true, classname); + classname = colorize(GRAY, true, classname); + classname = classname.replace('$', '.'); if (logDates) { Date d = new Date(); if (lastDate == null || d.getYear() != lastDate.getYear() || d.getMonth() != lastDate.getMonth() || d.getDay() != lastDate.getDay()) { String now = new java.text.SimpleDateFormat("EEE dd MMM yyyy").format(d); System.err.println(); - System.err.println(color(GRAY, false, "=== " + now + " ==========================================================")); + System.err.println(colorize(GRAY, false, "=== " + now + " ==========================================================")); } java.text.DateFormat df = new java.text.SimpleDateFormat("[EEE HH:mm:ss] "); classname = df.format(d) + classname; @@ -110,9 +109,9 @@ public class Log { try { String m = ""; while((s = br.readLine()) != null) m += s + "\n"; - log(o, m, level); + log(o, m.substring(0, m.length() - 1), level); } catch (IOException e) { - System.err.println(color(RED, true, "Logger: exception thrown by ByteArrayInputStream -- this should not happen")); + System.err.println(colorize(RED, true, "Logger: exception thrown by ByteArrayInputStream -- this should not happen")); } return; } @@ -121,7 +120,7 @@ public class Log { while(str.indexOf('\t') != -1) str = str.substring(0, str.indexOf('\t')) + " " + str.substring(str.indexOf('\t') + 1); - classname = color(GRAY, false, classname); + classname = colorize(GRAY, false, classname); int levelcolor = GRAY; boolean bright = true; switch (level) { @@ -134,27 +133,28 @@ public class Log { } while(str.indexOf('\n') != -1) { - System.err.println(classname + color(levelcolor, bright, str.substring(0, str.indexOf('\n')))); + System.err.println(classname + colorize(levelcolor, bright, str.substring(0, str.indexOf('\n')))); classname = logDates ? " " : " "; + classname = colorize(GRAY,false,classname); str = str.substring(str.indexOf('\n') + 1); } - System.err.println(classname + color(levelcolor, bright, str)); + System.err.println(classname + colorize(levelcolor, bright, str)); } public static void recursiveLog(String indent, String name, Object o) throws JSExn { if (!name.equals("")) name += " : "; if (o == null) { - Log.logJS(indent + name + ""); + JS.log(indent + name + ""); } else if (o instanceof JSArray) { - Log.logJS(indent + name + ""); + JS.log(indent + name + ""); JSArray na = (JSArray)o; for(int i=0; i"); + JS.log(indent + name + ""); JS s = (JS)o; Enumeration e = s.keys(); while(e.hasMoreElements()) { @@ -165,7 +165,7 @@ public class Log { s.get(((Integer)key)) : s.get(key.toString())); } } else { - Log.logJS(indent + name + o); + JS.log(indent + name + o); } }