From 7d45644e15a837386fe18331c36a647dcc17e839 Mon Sep 17 00:00:00 2001 From: crawshaw Date: Thu, 6 Jan 2005 16:02:27 +0000 Subject: [PATCH] update Log to use Baskets and remove deprecated API calls darcs-hash:20050106160227-2eb37-b39090be71ad40cfe4e69bc3abdb3d1d5d309403.gz --- src/org/ibex/util/Log.java | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/org/ibex/util/Log.java b/src/org/ibex/util/Log.java index 67163d9..2659b26 100644 --- a/src/org/ibex/util/Log.java +++ b/src/org/ibex/util/Log.java @@ -3,12 +3,29 @@ // You may not use this file except in compliance with the License. package org.ibex.util; -import java.io.*; + import java.util.*; -import java.net.*; -/** easy to use logger */ +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.net.Socket; +import java.net.InetAddress; +import java.text.SimpleDateFormat; + +/** Easy to use logger. + * + * @author adam@ibex.org + */ public class Log { + private static final SimpleDateFormat formatDate = new SimpleDateFormat("EEE dd MMM yyyy"); + private static final SimpleDateFormat formatTime = new SimpleDateFormat("[EEE HH:mm:ss] "); + private static final Hashtable threadAnnotations = new Hashtable(); public static boolean on = System.getProperty("ibex.log.on", "true").equals("true"); public static boolean color = System.getProperty("ibex.log.color", "true").equals("true"); @@ -18,7 +35,7 @@ public class Log { 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; + public static int lastDay = -1; public static PrintStream logstream = System.err; @@ -33,7 +50,6 @@ public class Log { logstream = new PrintStream(new Socket(InetAddress.getByName(host), port).getOutputStream()); } - private static Hashtable threadAnnotations = new Hashtable(); public static void setThreadAnnotation(String s) { threadAnnotations.put(Thread.currentThread(), s); } /** @@ -53,7 +69,8 @@ public class Log { } } public static void clearnotes() { if (!notes) return; notebuf().setLength(0); } - private static Hashtable notebufs = new Hashtable(); + + private static final Basket.Map notebufs = new Basket.HashMap(); public static StringBuffer notebuf() { StringBuffer ret = (StringBuffer)notebufs.get(Thread.currentThread()); if (ret == null) { @@ -138,15 +155,14 @@ public class Log { classname = classname.replace('$', '.'); if (logDates) { - Date d = new Date(); - if (lastDate == null || d.getYear() != lastDate.getYear() || d.getMonth() != lastDate.getMonth() || d.getDay() != lastDate.getDay()) { - String now = new java.text.SimpleDateFormat("EEE dd MMM yyyy").format(d); + Calendar cal = Calendar.getInstance(); + if (lastDay < 0 || lastDay != cal.get(Calendar.DAY_OF_YEAR)) { + lastDay = cal.get(Calendar.DAY_OF_YEAR); + String now = formatDate.format(cal.getTime()); logstream.println(); - logstream.println(colorize(GRAY, false, "=== " + now + " ==========================================================")); + logstream.println(colorize(GREEN, false, "=== " + now + " ==========================================================")); } - java.text.DateFormat df = new java.text.SimpleDateFormat("[EEE HH:mm:ss] "); - classname = df.format(d) + classname; - lastDate = d; + classname = formatTime.format(cal.getTime()) + classname; } String annot = (String)threadAnnotations.get(Thread.currentThread()); -- 1.7.10.4