From 8ba01b18add3bb34fc5f7f0775ac307a1a726bea Mon Sep 17 00:00:00 2001 From: Otis Gospodnetic Date: Sat, 14 Sep 2002 23:55:41 +0000 Subject: [PATCH] - Made attributes private, formatter final. - Added FIXME, added some Javadocs. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150819 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/de/lanlab/larm/util/SimpleLogger.java | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util/SimpleLogger.java b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util/SimpleLogger.java index 4b3e889510a..c36afeb0490 100644 --- a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util/SimpleLogger.java +++ b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util/SimpleLogger.java @@ -59,24 +59,47 @@ import java.util.*; import java.text.*; /** - * this class is only used for SPEED. Its log function is not thread safe by + * This class is only used for SPEED. Its log function is not thread safe by * default. * It uses a BufferdWriter. * It registers with a logger manager, which can be used to flush several loggers - * at once + * at once. * @todo: including the date slows down a lot - * + * @version $Id$ */ public class SimpleLogger { - private SimpleDateFormat formatter = new SimpleDateFormat ("HH:mm:ss:SSSS"); + private final SimpleDateFormat formatter = new SimpleDateFormat ("HH:mm:ss:SSSS"); - Writer logFile; + private Writer logFile; - StringBuffer buffer = new StringBuffer(1000); + private StringBuffer buffer = new StringBuffer(1000); - long startTime = System.currentTimeMillis(); - boolean includeDate; + private long startTime = System.currentTimeMillis(); + private boolean includeDate; + private boolean flushAtOnce = false; + + + /** + * Creates a new SimpleLogger instance. + * + * @param name a String value + */ + public SimpleLogger(String name) + { + init(name, true); + } + + /** + * Creates a new SimpleLogger instance. + * + * @param name a String value + * @param includeDate a boolean value + */ + public SimpleLogger(String name, boolean includeDate) + { + init(name, includeDate); + } public void setStartTime(long startTime) { @@ -98,13 +121,13 @@ public class SimpleLogger try { buffer.setLength(0); - if(includeDate) + if (includeDate) { buffer.append(formatter.format(new Date())).append(": ").append(System.currentTimeMillis()-startTime).append(" ms: "); } buffer.append(text).append("\n"); logFile.write(buffer.toString()); - if(flushAtOnce) + if (flushAtOnce) { logFile.flush(); } @@ -120,23 +143,11 @@ public class SimpleLogger t.printStackTrace(new PrintWriter(logFile)); } - boolean flushAtOnce = false; - public void setFlushAtOnce(boolean flush) { this.flushAtOnce = flush; } - public SimpleLogger(String name) - { - init(name, true); - } - - public SimpleLogger(String name, boolean includeDate) - { - init(name, includeDate); - } - public void flush() throws IOException { logFile.flush(); @@ -146,13 +157,14 @@ public class SimpleLogger { try { - logFile = new BufferedWriter(new FileWriter("logs/" + name + ".log")); - SimpleLoggerManager.getInstance().register(this); + // FIXME: the logs directory needs to be configurable + logFile = new BufferedWriter(new FileWriter("logs/" + name + ".log")); + SimpleLoggerManager.getInstance().register(this); } - catch(IOException e) + catch (IOException e) { - System.out.println("IOException while creating logfile " + name + ":"); - e.printStackTrace(); + System.out.println("IOException while creating logfile " + name + ":"); + e.printStackTrace(); } } }