X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Futil%2FLog.java;h=1eb61ef0f5f400923cb4e4c3718335253939a444;hb=1468496caebca328c762ef4d0a26b62650af4442;hp=71fb1edeb3f672976c3a0d5ef4649e8f3e114065;hpb=027607da259f292060d80e0ed90d2b0e896acd86;p=org.ibex.core.git diff --git a/src/org/xwt/util/Log.java b/src/org/xwt/util/Log.java index 71fb1ed..1eb61ef 100644 --- a/src/org/xwt/util/Log.java +++ b/src/org/xwt/util/Log.java @@ -1,5 +1,12 @@ -// Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL] +// Copyright (C) 2003 Adam Megacz all rights reserved. +// +// You may modify, copy, and redistribute this code under the terms of +// the GNU Library Public License version 2.1, with the exception of +// the portion of clause 6a after the semicolon (aka the "obnoxious +// relink clause") + package org.xwt.util; +import org.xwt.js.*; import java.io.*; import java.util.*; @@ -14,9 +21,34 @@ 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); } + + 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 log(Object o, Object message) { - if (firstMessage && !logDates) { firstMessage = false; System.err.println("==========================================================================="); @@ -45,21 +77,57 @@ public class Log { lastDate = d; } - if (!(message instanceof Throwable)) System.err.println(classname + message); - else { + + if (message instanceof Throwable) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ((Throwable)message).printStackTrace(new PrintStream(baos)); byte[] b = baos.toByteArray(); BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b))); String s = null; try { - while((s = br.readLine()) != null) { - System.err.print(classname); - for(int i=0; i"); + + } else if (o instanceof JSArray) { + Log.logJS(indent + name + ""); + JSArray na = (JSArray)o; + for(int i=0; i"); + 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); } }