lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene-sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util SimpleLogger.java
Date Sat, 14 Sep 2002 23:55:41 GMT
otis        2002/09/14 16:55:41

  Modified:    contributions/webcrawler-LARM/src/de/lanlab/larm/util
                        SimpleLogger.java
  Log:
  - Made attributes private, formatter final.
  - Added FIXME, added some Javadocs.
  
  Revision  Changes    Path
  1.3       +39 -27    jakarta-lucene-sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util/SimpleLogger.java
  
  Index: SimpleLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/util/SimpleLogger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleLogger.java	22 May 2002 23:09:19 -0000	1.2
  +++ SimpleLogger.java	14 Sep 2002 23:55:41 -0000	1.3
  @@ -59,24 +59,47 @@
   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 <code>SimpleLogger</code> instance.
  +     *
  +     * @param name a <code>String</code> value
  +     */
  +    public SimpleLogger(String name)
  +    {
  +        init(name, true);
  +    }
  +
  +    /**
  +     * Creates a new <code>SimpleLogger</code> instance.
  +     *
  +     * @param name a <code>String</code> value
  +     * @param includeDate a <code>boolean</code> value
  +     */
  +    public SimpleLogger(String name, boolean includeDate)
  +    {
  +        init(name, includeDate);
  +    }
   
       public void setStartTime(long startTime)
       {
  @@ -98,13 +121,13 @@
           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 @@
           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 @@
       {
           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();
           }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message