MDi JLib
1.7.4

com.microdeveloper.util.io.log
Class ErrorLog

java.lang.Object
  extended by com.microdeveloper.util.io.log.ErrorLog
All Implemented Interfaces:
Serializable

public class ErrorLog
extends Object
implements Serializable

ErrorLog provides a consolidated class for error handling and output.

To use ErrorLog, create a log instance:

and then when the error occurs:

The time and date will be added to your message and written to System.err.

If you have different levels of severity you wish to keep track of, you can create different ErrorLog objects:

Since:
1.7.4
Version:
1.0
Author:
MicroDeveloper, Inc.
See Also:
Serialized Form

Constructor Summary
ErrorLog()
          Create an ErrorLog object where errors are sent to System.err
ErrorLog(String fileName)
          Create an ErrorLog object where errors are sent to a text file.
 
Method Summary
 void add(String message)
          Add an error message to the ErrorLog object.
 void appendLogFile(String fileName)
          Tell the ErrorLog object that all future error messages are to be copied to a text file.
 String[] getList()
          Get a list of all error messages that have been passed in to the ErrorLog object.
 boolean isConsoleLogOn()
          Test to see if this ErrorLog object currently copies error messages to the console.
 boolean isFileLogOn()
          Test to see if this ErrorLog object currently copies error messages to a text file.
 boolean isInternalLogOn()
          Test to see if this ErrorLog object currently copies error messages to an internal buffer.
 int numErrors()
          Get the number of errors that this object has encountered.
 void setConsole(boolean on)
          Tell the ErrorLog object to start/stop copying error messages to the console.
 void setInternalLog(boolean on)
          Tell the ErrorLog object to start/stop copying error messages to an internal buffer.
 void setLogFile(String fileName)
          Tell the ErrorLog object that all future error messages are to be copied to a text file.
 void setLogFileOff()
          Tell the ErrorLog object that no further errors are to be copied to a text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ErrorLog

public ErrorLog()
Create an ErrorLog object where errors are sent to System.err


ErrorLog

public ErrorLog(String fileName)
         throws IOException
Create an ErrorLog object where errors are sent to a text file.

If the text file already exists, it will first be deleted. If the text file does not already exist, it will be created.

This constructor defaults to console logging off. If you want both console logging and file logging, call this constructor and then call setConsole( true );

Parameters:
fileName - The name of the file that will be created and store future error messages.

Throws:
IOException - thrown for any IO errors encountered while creating the file.

Method Detail

setLogFile

public void setLogFile(String fileName)
                throws IOException
Tell the ErrorLog object that all future error messages are to be copied to a text file.

If the text file already exists, it will first be deleted. If the text file does not already exist, it will be created.

Parameters:
fileName - The name of the file that will be created and store future error messages.

Throws:
IOException - thrown for any IO errors encountered while creating the file.


appendLogFile

public void appendLogFile(String fileName)
                   throws IOException
Tell the ErrorLog object that all future error messages are to be copied to a text file.

If the text file already exists, new messages will be appended to the end. If the text file does not already exist, it will be created.

Parameters:
fileName - The name of the file that will store future error messages.

Throws:
IOException - thrown for any IO errors encountered while creating/opening the file.


setLogFileOff

public void setLogFileOff()
Tell the ErrorLog object that no further errors are to be copied to a text file.

This method also properly closes the log file.


isFileLogOn

public boolean isFileLogOn()
Test to see if this ErrorLog object currently copies error messages to a text file.

Returns:
true if all messages are copied to a text file.
false if no messages are copied to a text file.


setConsole

public void setConsole(boolean on)
Tell the ErrorLog object to start/stop copying error messages to the console.

Parameters:
on - true: start sending messages to the console. false: stop sending messages to the console.


isConsoleLogOn

public boolean isConsoleLogOn()
Test to see if this ErrorLog object currently copies error messages to the console.

Returns:
true if all messages are copied to the console.
false if no messages are copied to the console.


add

public void add(String message)
Add an error message to the ErrorLog object.

"message" has a time/date stamp added to it.

If internal logging is on, the message is appended to the internal collection of error messages.

If console logging is on, the message is copied to the console.

If file logging is on, the message is copied to the log file.

Parameters:
message - this can be any text you want.


numErrors

public int numErrors()
Get the number of errors that this object has encountered.

Returns:
the number of error that this object has encountered.


getList

public String[] getList()
Get a list of all error messages that have been passed in to the ErrorLog object.

Returns:
an array of strings which represent the error messages that were passed to the ErrorLog object. Each message includes a date and time stamp. If errors are not currently stored in this object, null is returned.


setInternalLog

public void setInternalLog(boolean on)
Tell the ErrorLog object to start/stop copying error messages to an internal buffer.

Parameters:
on - true start copying messages to the internal buffer. false stop copying messages to the internal buffer.

isInternalLogOn

public boolean isInternalLogOn()
Test to see if this ErrorLog object currently copies error messages to an internal buffer.

Returns:
true if all messages are copied to the internal buffer.
false if no messages are copied to the internal buffer.


MDi JLib
1.7.4

Copyright©2001-2007 MicroDeveloper, Inc. All Rights Reserved.