com.denova.io
Class Log

java.lang.Object
  |
  +--com.denova.io.Log

public class Log
extends java.lang.Object

Record messages to a log, if the log file exists. This is a great diagnostic tool that allows you to have debugging messages in your custom classes which only appear if a customer is having a problem and they create the appropriately named log file. All log files end with .log and are case sensitive. Copyright © 1997-2008 DeNova All rights reserved worldwide. Last modified: 2008.04.15


Constructor Summary
Log(java.io.File directory, java.lang.String logName)
          Records messages in a text file.
Log(java.lang.String logName)
          Records messages in a text file in the user's directory as defined by the System properties.
Log(java.lang.String directory, java.lang.String logName)
          Records messages in a text file.
 
Method Summary
 void end()
          Closes the log file and stops logging until startLogging() called.
 void flush()
          Forces the file system to save all messages to disk.
 com.denova.io.Log getAlsoLogTo()
          Returns an alternate log file where messages are being saved.
static boolean getAlwaysFlush()
          Get whether to write the buffer to disk after every update or not.
static java.lang.String getLogDir()
          Get the name of the directory where logs are.
 boolean getLogging()
          Returns true if logging forced, even if file does not exist.
 com.denova.ui.TextDisplayable getStatusDisplay()
          Returns the text display area that was set with setStatusDisplay().
static boolean getUseTempDirectory()
          Get whether to write the log in a temporary directory or not.
 boolean logFileExists()
          Returns true iff log file exists.
 void setAlsoLogTo(com.denova.io.Log log2)
          Lets you save the same messages to another log file.
static void setAlwaysFlush(boolean flush)
          Set whether to write the buffer to disk after every update or not.
static void setLogDir(java.lang.String dirname)
          Sets the directory where to save log files.
 void setLogging(boolean logNow)
          Set whether to record log messages.
 void setStatusDisplay(com.denova.ui.TextDisplayable where)
          Sets a displayable window for write() calls.
static void setUseTempDirectory(boolean use)
          Set whether to write the log in a temporary directory or not.
 void startLogging()
          Starts logging so all future calls to write() save the messages.
 void stopLogging()
          Closes log file and stops logging.
 void write(java.lang.Exception e)
          Saves the text from a Exception exception to the log file.
 void write(java.lang.String s)
          Saves a message to the log file.
 void write(java.lang.Throwable e)
          Saves the text from a Throwable exception to the log file.
 void write(java.lang.Throwable e, java.lang.String msg)
          Saves a message and the text from an exception to the log file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log

public Log(java.lang.String directory,
           java.lang.String logName)
Records messages in a text file.

If the file exists, then messages are appended to the file.
Messages are only saved in the file if the file already exists when Log instantiated or you call startLogging ().

Parameters:
directory - to write log.
logName - filename of log, without path.

Log

public Log(java.io.File directory,
           java.lang.String logName)
Records messages in a text file.

If the file exists, then messages are appended to the file.
Messages are only saved in the file if the file already exists when Log instantiated or you call startLogging ().

Parameters:
directory - where to store log.
logName - filename of log, without path.

Log

public Log(java.lang.String logName)
Records messages in a text file in the user's directory as defined by the System properties.

If the file exists, then messages are appended to the file.
Messages are only saved in the file if the file already exists when Log instantiated or you call startLogging ().

Parameters:
logName - filename of log, without path.
Method Detail

setLogDir

public static void setLogDir(java.lang.String dirname)
Sets the directory where to save log files.

Parameters:
dirname - name of directory.

getLogDir

public static java.lang.String getLogDir()
Get the name of the directory where logs are.

Returns:
name of directory for log.

setAlwaysFlush

public static void setAlwaysFlush(boolean flush)
Set whether to write the buffer to disk after every update or not.

Parameters:
flush - state of whether to flush the log

getAlwaysFlush

public static boolean getAlwaysFlush()
Get whether to write the buffer to disk after every update or not.

Returns:
true if the log is always written to disk after every update.

setUseTempDirectory

public static void setUseTempDirectory(boolean use)
Set whether to write the log in a temporary directory or not.

Parameters:
use - true if you want the log created in a temporary directory.

getUseTempDirectory

public static boolean getUseTempDirectory()
Get whether to write the log in a temporary directory or not.

Returns:
true if you want the log created in a temporary directory.

end

public void end()
Closes the log file and stops logging until startLogging() called.


write

public void write(java.lang.String s)
Saves a message to the log file.

Logging must be enabled when you call this member function. Logging is automatically enabled if the file exists when you instantiate Log or you invoke startLogging() or setLogging( true ).

Parameters:
s - message

write

public void write(java.lang.Exception e)
Saves the text from a Exception exception to the log file.

Logging must be enabled when you call this member function. Logging is automatically enabled if the file exists when you instantiate Log or you invoke startLogging().

Parameters:
e - exception error

write

public void write(java.lang.Throwable e)
Saves the text from a Throwable exception to the log file.

Logging must be enabled when you call this member function. Logging is automatically enabled if the file exists when you instantiate Log or you invoke startLogging().

Parameters:
e - throwable error

write

public void write(java.lang.Throwable e,
                  java.lang.String msg)
Saves a message and the text from an exception to the log file.

Logging must be enabled when you call this member function. Logging is automatically enabled if the file exists when you instantiate Log or you invoke startLogging().

Parameters:
e - exception error
msg - message about error

getLogging

public boolean getLogging()
Returns true if logging forced, even if file does not exist.

Returns:
The logging value

setLogging

public void setLogging(boolean logNow)
Set whether to record log messages.

Parameters:
logNow - The new logging value

getStatusDisplay

public com.denova.ui.TextDisplayable getStatusDisplay()
Returns the text display area that was set with setStatusDisplay().

Returns null if setStatusDisplay() was never called.

Returns:
The statusDisplay value

setStatusDisplay

public void setStatusDisplay(com.denova.ui.TextDisplayable where)
Sets a displayable window for write() calls.

When logging is active, then all calls to write() also display in text display area.

Parameters:
where - The new statusDisplay value

getAlsoLogTo

public com.denova.io.Log getAlsoLogTo()
Returns an alternate log file where messages are being saved.

If setAlsoLogTo() wasn't called previously, then returns null.

Returns:
The alsoLogTo value

setAlsoLogTo

public void setAlsoLogTo(com.denova.io.Log log2)
Lets you save the same messages to another log file.

Parameters:
log2 - The new alsoLogTo value

startLogging

public void startLogging()
Starts logging so all future calls to write() save the messages.

If the log file doesn't exist, then it automatically creates it.
If the log file does exist, then all messages will be appended to it.


stopLogging

public void stopLogging()
Closes log file and stops logging.

All future calls to write() are ignored.


flush

public void flush()
Forces the file system to save all messages to disk.


logFileExists

public boolean logFileExists()
Returns true iff log file exists.