- /** 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); }
-
- public static BufferedReader loggedReader(Reader r) {
- // FIXME
- return new BufferedReader(r);
- /*
- new BufferedReader(new FilterReader(new InputStreamReader(is)) {
- public int read() throws IOException {
- int i = super.read();
- if (Log.on) Log.log(this, "recv: " + ((char)i));
- return i;
- }
- public int read(char[] c, int off, int len) throws IOException {
- int ret = super.read(c, off, len);
- if (ret == -1) return ret;
- String s;
- BufferedReader br2 = new BufferedReader(new StringReader(new String(c, off, ret)));
- while ((s = br2.readLine()) != null) Log.log(this, "recv: " + s);
- return ret;
- }
- });
- */
+ /** 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); }
+ 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;
+ private static final int ECHO = -1;
+
+ // the usual log4j levels, minus FAIL (we just throw an Error in that case)
+ private static final int DEBUG = 0;
+ private static final int INFO = 1;
+ private static final int WARN = 2;
+ private static final int ERROR = 3;
+
+ private static final int BLACK = 30;
+ private static final int BLUE = 34;
+ private static final int GREEN = 32;
+ private static final int CYAN = 36;
+ private static final int RED = 31;
+ private static final int PURPLE = 35;
+ private static final int BROWN = 33;
+ private static final int GRAY = 37;
+
+ private static String colorize(int color, boolean bright, String s) {
+ if (!Log.color) return s;
+ return
+ "\033[40;" + (bright?"1;":"") + color + "m" +
+ s +
+ "\033[0m";