licensing update to APSL 2.0
[org.ibex.util.git] / src / org / ibex / util / Log.java
index 70f1054..67163d9 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2003 Adam Megacz <adam@ibex.org> 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")
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
 
 package org.ibex.util;
-import org.ibex.js.*;
 import java.io.*;
 import java.util.*;
 import java.net.*;
@@ -19,6 +15,7 @@ public class Log {
     public static boolean verbose       = System.getProperty("ibex.log.verbose", "false").equals("true");
     public static boolean logDates      = System.getProperty("ibex.log.dates", "false").equals("true");
     public static boolean notes         = System.getProperty("ibex.log.notes.on", "true").equals("true");
+    public static boolean stackTraces   = System.getProperty("ibex.log.stackTraces", "true").equals("true");
     public static int maximumNoteLength = Integer.parseInt(System.getProperty("ibex.log.notes.maximumLength", (1024 * 32)+""));
     public static boolean rpc           = false;
     public static Date lastDate = null;
@@ -57,7 +54,7 @@ public class Log {
     }
     public static void clearnotes() { if (!notes) return; notebuf().setLength(0); }
     private static Hashtable notebufs = new Hashtable();
-    private static StringBuffer notebuf() {
+    public static StringBuffer notebuf() {
         StringBuffer ret = (StringBuffer)notebufs.get(Thread.currentThread());
         if (ret == null) {
             ret = new StringBuffer(16 * 1024);
@@ -169,16 +166,34 @@ public class Log {
             }
             byte[] b = baos.toByteArray();
             BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b)));
-            String s = null;
             try {
-                String m = "";
-                while((s = br.readLine()) != null) m += s + "\n";
-                if (m.length() > 0) log(o, m.substring(0, m.length() - 1), level);
+                if (stackTraces) {
+                    String s = null;
+                    String m = "";
+                    while((s = br.readLine()) != null) m += s + "\n";
+                    if (m.length() > 0) log(o, m.substring(0, m.length() - 1), level);
+                } else {
+                    String m = br.readLine();
+                    int ok = 0;
+                    do {
+                        String s = br.readLine();
+                        if (s == null) break;
+                        if (s.indexOf('(') != -1) {
+                            String shortened = s.substring(s.indexOf('(')+1);
+                            shortened = shortened.substring(0, shortened.indexOf(')'));
+                            m += " " + shortened;
+                            if (ok > 1) m = m.substring(0, 78);
+                            ok++;
+                        }
+                    } while (m.length() < 78);
+                    log(o, m, level);
+                }
+                lastClassName = "";
             } catch (IOException e) {
                 // FEATURE: use org.ibex.io.Stream's here
-                logstream.println(colorize(RED, true, "Logger: exception thrown by ByteArrayInputStream; this should not happen"));
+                logstream.println(colorize(RED, true, "Logger: exception thrown by ByteArrayInputStream;" +
+                                           " this should not happen"));
             }
-            lastClassName = "";
             return;
         }
 
@@ -208,33 +223,4 @@ public class Log {
         logstream.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) {
-            JS.log(indent + name + "<null>");
-
-        } else if (o instanceof JSArray) {
-            JS.log(indent + name + "<array>");
-            JSArray na = (JSArray)o;
-            for(int i=0; i<na.length(); i++)
-                recursiveLog(indent + "  ", i + "", na.elementAt(i));
-
-        } else if (o instanceof JS) {
-            JS.log(indent + name + "<object>");
-            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 {
-            JS.log(indent + name + o);
-
-        }
-    }
-
 }