X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Futil%2FLog.java;h=329382f92bbcd24707c0483e6a4c4a8d3a8b70ce;hb=3ed548fd4a192e962518da7756741eb8c44bd529;hp=e53625257c03f20c2de65d9a44a973434873d6e9;hpb=62b09c2447b9516863916b076fe64fe98ec1670f;p=org.ibex.core.git diff --git a/src/org/xwt/util/Log.java b/src/org/xwt/util/Log.java index e536252..329382f 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; @@ -24,6 +24,7 @@ public class Log { /** 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); } @@ -47,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) { + 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 " + + 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; @@ -82,6 +84,7 @@ public class Log { while (classname.length() < (logDates ? 14 : 20)) classname = " " + classname; classname = classname + (classname.trim().length() == 0 ? " " : ": "); classname = color(GRAY, true, classname); + classname = classname.replace('$', '.'); if (logDates) { Date d = new Date(); @@ -106,7 +109,7 @@ 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")); } @@ -132,6 +135,7 @@ public class Log { while(str.indexOf('\n') != -1) { System.err.println(classname + color(levelcolor, bright, str.substring(0, str.indexOf('\n')))); classname = logDates ? " " : " "; + classname = color(GRAY,false,classname); str = str.substring(str.indexOf('\n') + 1); } System.err.println(classname + color(levelcolor, bright, str));