# HG changeset patch # User xitiomet # Date 1304580308 14400 # Node ID 58a8ff544b6412bba09e9990abe2284ab77f9467 # Parent fb2f5e689d8d0aca72aeedc6fea406f650dc60e4 more logging fixes diff -r fb2f5e689d8d0aca72aeedc6fea406f650dc60e4 -r 58a8ff544b6412bba09e9990abe2284ab77f9467 src/org/openstatic/util/LiquidLogger.java --- a/src/org/openstatic/util/LiquidLogger.java Thu May 05 02:49:03 2011 -0400 +++ b/src/org/openstatic/util/LiquidLogger.java Thu May 05 03:25:08 2011 -0400 @@ -4,43 +4,48 @@ import java.io.ByteArrayOutputStream; import java.util.Date; import java.util.StringTokenizer; +import java.util.Hashtable; +import java.util.Enumeration; import java.text.SimpleDateFormat; public class LiquidLogger { + private Hashtable inbound; + private PrintStream outbound; private PrintStream inbound_ps; - private ByteArrayOutputStream inbound; - private PrintStream outbound; - private String caption; public LiquidLogger(PrintStream display) { - this.inbound = new ByteArrayOutputStream(); - this.inbound_ps = new PrintStream(inbound,true); + this.inbound = new Hashtable(); + this.inbound_ps = this.getPrintStream("debug"); this.outbound = display; - this.caption = ""; Thread t = new Thread() { public void run() { while(true) { - if (LiquidLogger.this.inbound.size() > 0 && LiquidLogger.this.outbound != null) + for (Enumeration keys = LiquidLogger.this.inbound.keys(); keys.hasMoreElements(); ) { - StringTokenizer st = new StringTokenizer(LiquidLogger.this.inbound.toString(), "\n"); - LiquidLogger.this.inbound.reset(); - while (st.hasMoreTokens()) + String caption = keys.nextElement(); + ByteArrayOutputStream baos = LiquidLogger.this.inbound.get(caption); + if (baos.size() > 0 && LiquidLogger.this.outbound != null) { - SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"); - String date_time = df.format(new Date()); - String msg = st.nextToken(); - String temp_caption = LiquidLogger.this.caption; - if (msg.startsWith("[") && msg.contains("]")) + StringTokenizer st = new StringTokenizer(baos.toString(), "\n"); + baos.reset(); + while (st.hasMoreTokens()) { - temp_caption = msg.substring(msg.indexOf("[")+1, msg.indexOf("]")); - msg = msg.substring(msg.indexOf("]")+1); + SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"); + String date_time = df.format(new Date()); + String msg = st.nextToken(); + String temp_caption = caption; + if (msg.startsWith("[") && msg.contains("]")) + { + temp_caption = msg.substring(msg.indexOf("[")+1, msg.indexOf("]")); + msg = msg.substring(msg.indexOf("]")+1); + } + LiquidLogger.this.outbound.println("<" + setSizedString(date_time,23) + "> [ " + setSizedString(temp_caption, 16) + " ] " + msg.replaceAll("\r","")); } - LiquidLogger.this.outbound.println("<" + setSizedString(date_time,23) + "> [ " + setSizedString(temp_caption, 16) + " ] " + msg.replaceAll("\r","")); } } try @@ -58,15 +63,18 @@ this.outbound = display; } - public void setCaption(String caption) - { - this.caption = caption; - } - public PrintStream getPrintStream() { return this.inbound_ps; } + + public PrintStream getPrintStream(String caption) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream z = new PrintStream(baos, true); + this.inbound.put(caption, baos); + return z; + } public void println(String text) {