edu.ucsb.adl.bucket99
Class Log

java.lang.Object
  |
  +--edu.ucsb.adl.bucket99.Log

public final class Log
extends java.lang.Object

Appends time-stamped records to a log file or to a Java logger. Each record consists of a single line delimited by a newline character, and has the following internal structure:

!field|field|...|field
Within fields, the exclamation point ('!'), vertical bar ('|'), percent sign ('%'), and newline characters only are escaped in the style of java.net.URLEncoder. The first field of every record is the time the record was logged in the semantics of System.currentTimeMillis; the second field is the type of the record; and the third field is the name of the entity that logged the record. The remaining fields (if any) are undefined by this class and may vary from record to record.

This class is multithread-safe.

Version:
$Header: /export/home/gjanee/bucket99/edu/ucsb/adl/bucket99/RCS/Log.java,v 1.3 2003/06/13 04:24:20 gjanee Exp $

$Log: Log.java,v $ Revision 1.3 2003/06/13 04:24:20 gjanee
Added support for logging to Java loggers. If the log filename has the form "j2se-logger:L" records are logged to Java logger L at logging level INFO.

Revision 1.2 2003/06/12 15:25:12 gjanee
Minor recoding to avoid using a deprecated method.

Revision 1.1 2000/05/03 05:10:19 gjanee
Initial revision

Author:
Greg Janée
Alexandria Digital Library

Method Summary
 void close()
          Decrements the reference count.
 void log(java.lang.String recordType, java.lang.String caller, java.lang.String[] fields)
          Appends a record to the log file.
static edu.ucsb.adl.bucket99.Log openLog(java.lang.String filename)
          Opens a log file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openLog

public static edu.ucsb.adl.bucket99.Log openLog(java.lang.String filename)
                                         throws java.io.IOException
Opens a log file. If a Log already exists for filename, its reference count is incremented and it is returned instead. Otherwise, a new Log is created and filename is opened for append.

Parameters:
filename - The log file's filename; or, if the value is of the form "j2se-logger:L", the name L of a Java Logger to write to (at logging level INFO).
Throws:
java.io.IOException - If the log file can't be opened.

log

public void log(java.lang.String recordType,
                java.lang.String caller,
                java.lang.String[] fields)
         throws java.io.IOException
Appends a record to the log file.

Parameters:
recordType - The type of record.
caller - The name of the entity doing the logging.
fields - Additional fields to log, or null.
Throws:
java.io.IOException - If an I/O error occurs.

close

public void close()
           throws java.io.IOException
Decrements the reference count. When the reference count drops to zero, the log file is closed.

Throws:
java.io.IOException - If an error occurs closing the log file.