org.ceryle.util.log
Class Logger

java.lang.Object
  extended by org.ceryle.util.log.Logger

public class Logger
extends Object

A singleton class that writes to a log file. This is designed as a simple logger, with none of the complexity of say, the new Java Logging API.

The two properties this class responds to are:

message.verbose
When true, messaging is set to verbose mode.
http://purl.org/ceryle/log/properties/log-active
When true, indicates logging should be active.
http://purl.org/ceryle/log/properties/log.append
When true, log messages are appended to the existing log rather than overwriting a new one.

Log Filename

The constructor's filename parameter is optional. If it is not provided, a check for a System property "ceryle.log.filename" will be made. Absent a provided value, the default LOG_FILENAME ("application.log") will be used.

This class will be deprecated and replaced with Log4J.

Since:
JDK1.3
Version:
$Id: Logger.java,v 3.10 2007-06-15 12:10:02 altheim Exp $
Author:
Murray Altheim

Field Summary
static boolean autoflush
          When true, flushes after each write.
static String LOG_ACTIVE
          Feature identifier: log active.
static String LOG_APPEND
          Feature identifier: log append.
 String LOG_CLOSE_CODE
          Single character state code indicating a close log message.
 String LOG_ERROR_CODE
          Single character state code indicating an error message.
 String LOG_FATAL_CODE
          Single character state code indicating a fatal message.
static String LOG_FEATURE_PFX
          Logger Feature prefix.
static String LOG_FILENAME
          The default filename for the log file.
 String LOG_OK_CODE
          Single character state code indicating a normal log message.
 String LOG_OPEN_CODE
          Single character state code indicating an open log message.
static String LOG_PROPERTY_FILENAME
          Log filename property identifier.
 String LOG_UNKNOWN_CODE
          Single character state code indicating an unknown state, or simply a log message.
 String LOG_WARNING_CODE
          Single character state code indicating a warning message.
static double logMaxSize
          The size limit of the log file (in MB).
static char RDELIM
          The record delimiter character used (at beginning of line).
 
Method Summary
 void close()
          Closes the log file if open.
 void flush()
          Flush the writer.
static Properties getDefaultProperties()
          Return the default properties for the Logger.
static Logger getInstance(MessageHandler messagehandler, String filename, Properties properties)
          As this is a singleton class, this returns the single instance of this class.
 double getLogFileLength()
          Returns the length of the log file (in MB).
 String getLogFileName()
          Returns the name of the log file (in MB).
 Writer getWriter()
          Returns the writer.
 void open()
          Opens log file for writing, defining the internal Writer.
 String write(String message)
          Write the String message to the current log file if active, returning the message value.
 String write(String timestamp, String message)
          Write the String message to the current log file if active, returning the message value.
 String write(String state, String timestamp, String message)
          Write the String message to the current log file if active, returning the message value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_PROPERTY_FILENAME

public static final String LOG_PROPERTY_FILENAME
Log filename property identifier.

See Also:
Constant Field Values

LOG_FEATURE_PFX

public static final String LOG_FEATURE_PFX
Logger Feature prefix.

See Also:
Constant Field Values

LOG_ACTIVE

public static final String LOG_ACTIVE
Feature identifier: log active.

See Also:
Constant Field Values

LOG_APPEND

public static final String LOG_APPEND
Feature identifier: log append.

See Also:
Constant Field Values

LOG_FILENAME

public static final String LOG_FILENAME
The default filename for the log file. The value is "application.log".

See Also:
Constant Field Values

logMaxSize

public static double logMaxSize
The size limit of the log file (in MB). Services provides a warning and option to delete the log, should the size increase above this limit. Default is 5 (5MB).


autoflush

public static boolean autoflush
When true, flushes after each write.


LOG_UNKNOWN_CODE

public final String LOG_UNKNOWN_CODE
Single character state code indicating an unknown state, or simply a log message. Value is "L".

See Also:
Constant Field Values

LOG_OPEN_CODE

public final String LOG_OPEN_CODE
Single character state code indicating an open log message. Value is "O".

See Also:
Constant Field Values

LOG_CLOSE_CODE

public final String LOG_CLOSE_CODE
Single character state code indicating a close log message. Value is "C".

See Also:
Constant Field Values

LOG_OK_CODE

public final String LOG_OK_CODE
Single character state code indicating a normal log message. Value is "M".

See Also:
Constant Field Values

LOG_WARNING_CODE

public final String LOG_WARNING_CODE
Single character state code indicating a warning message. Value is "W".

See Also:
Constant Field Values

LOG_ERROR_CODE

public final String LOG_ERROR_CODE
Single character state code indicating an error message. Value is "E".

See Also:
Constant Field Values

LOG_FATAL_CODE

public final String LOG_FATAL_CODE
Single character state code indicating a fatal message. Value is "F".

See Also:
Constant Field Values

RDELIM

public static final char RDELIM
The record delimiter character used (at beginning of line).

See Also:
Constant Field Values
Method Detail

getDefaultProperties

public static Properties getDefaultProperties()
Return the default properties for the Logger. This flags the log append property as true.


getInstance

public static Logger getInstance(MessageHandler messagehandler,
                                 String filename,
                                 Properties properties)
                          throws IOException
As this is a singleton class, this returns the single instance of this class. If filename is null, the default will be used.

Throws:
IOException

write

public String write(String message)
Write the String message to the current log file if active, returning the message value.


write

public String write(String timestamp,
                    String message)
Write the String message to the current log file if active, returning the message value. The String for timestamp is optional, as it will be generated if null.


write

public String write(String state,
                    String timestamp,
                    String message)
Write the String message to the current log file if active, returning the message value. The Strings for state and timestamp are optional. If timestamp is null it will be generated.


open

public void open()
          throws IOException
Opens log file for writing, defining the internal Writer. The internal Writer is opened upon class instantiation, so unless the Writer is closed via close(), this method has no effect.

Throws:
IOException

getLogFileName

public String getLogFileName()
Returns the name of the log file (in MB). If unable to obtain the File, a null is returned.


getLogFileLength

public double getLogFileLength()
Returns the length of the log file (in MB). If unable to obtain the File, a zero is returned.


getWriter

public Writer getWriter()
Returns the writer. This is used only for synchronization.


flush

public void flush()
           throws IOException
Flush the writer.

Throws:
IOException

close

public void close()
           throws IOException
Closes the log file if open.

Throws:
IOException


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.