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) {
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<s.length(); i++)
- System.err.print(s.charAt(i) == '\t' ? " " : ("" + s.charAt(i)));
- System.err.println();
- }
- } catch (Exception e) { }
+ while((s = br.readLine()) != null) log(o, s);
+ } catch (IOException e) {
+ System.err.println("Logger: exception thrown by ByteArrayInputStream -- this should not happen");
+ }
+ return;
+ }
+
+ String str = message.toString();
+ while(str.indexOf('\t') != -1)
+ str = str.substring(0, str.indexOf('\t')) + " " + str.substring(str.indexOf('\t') + 1);
+ while(str.indexOf('\n') != -1) {
+ System.err.println(classname + str.substring(0, str.indexOf('\n')));
+ str = str.substring(str.indexOf('\n') + 1);
}
+ System.err.println(classname + str);
}
public static void recursiveLog(String indent, String name, Object o) throws JSExn {