org.iperg.part.log.j2se
Class IpFileLogManager

java.lang.Object
  extended by org.iperg.part.log.j2se.IpFileLogManager
All Implemented Interfaces:
IpLogManager

public class IpFileLogManager
extends java.lang.Object
implements IpLogManager

The file log manager will store log messages on files. There is a limit for how large a log file may become. If the current file used by the manager to log messages exceeds this size limit, the manager will allocate a new file and continue to write messages to this file instead. There is also a limit for how many log files the manager is allowed to allocate. If this limit is exceeded, the oldest log file is deleted when a new file is allocated.

For example, assume that the maximum number of log files is 3, and that the log file name is 'partlog'. The following events will then occur at various points in time (T1 < T2 < T3 ...)


Constructor Summary
IpFileLogManager(java.lang.String applName)
          Create a file log manager that will use default values for log file directory, name, size limit and max file count.
IpFileLogManager(java.lang.String logFileDir, java.lang.String logFileName, int logFileSizeLimit, int maxNrOfLogFiles, java.lang.String applName)
          Create a new file log manager.
 
Method Summary
 java.lang.String getLogFileDirectory()
          Get the directory in which log files are written.
 java.lang.String getLogFileName()
          Get the file name used by the manager when creating log files.
 int getLogFileSizeLimit()
          Get the current size limit of log files in kilobytes.
 int getMaxNrOfLogFiles()
          Get the maximum number of log files that the manager can use when writing logs.
 void log(java.lang.String message)
          Write a message to the log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IpFileLogManager

public IpFileLogManager(java.lang.String logFileDir,
                        java.lang.String logFileName,
                        int logFileSizeLimit,
                        int maxNrOfLogFiles,
                        java.lang.String applName)
Create a new file log manager. Whenever the manager create a new log file, it will print a header in the file consisting of the time and date when the file was created, the name of the log file and the application name (as given by the applName parameter).

Parameters:
logFileDir - Directory where log files will be placed. If null, the default directory will be used.
logFileName - The log file name. If null, the default file name will be used.
logFileSizeLimit - Max size of log file in kilobytes. If <= 0, the default file size limit will be used.
maxNrOfLogFiles - Maximum number of log files that the manager will create, must be >= 2. If < 2, the default maximum number of log files will be used.
applName - A name that will be printed in the log file header to ease identification when browsing files. May be null.

IpFileLogManager

public IpFileLogManager(java.lang.String applName)
Create a file log manager that will use default values for log file directory, name, size limit and max file count. Whenever the manager create a new log file, it will print a header in the file consisting of the time and date when the file was created, the name of the log file and the application name (as given by the applName parameter).

Parameters:
applName - A name that will be printed in the log file header to ease identification when browsing files. May be null.
Method Detail

getLogFileName

public java.lang.String getLogFileName()
Get the file name used by the manager when creating log files.

Returns:
The log file name

getLogFileDirectory

public java.lang.String getLogFileDirectory()
Get the directory in which log files are written.

Returns:
The log file directory

getLogFileSizeLimit

public int getLogFileSizeLimit()
Get the current size limit of log files in kilobytes.

Returns:
Size limit

getMaxNrOfLogFiles

public int getMaxNrOfLogFiles()
Get the maximum number of log files that the manager can use when writing logs. When the current log file is full (as determined by the file size limit returned by the getFileSizeLimit method), the manager will create a new file and continue logging messages on this file. This behaviour will continue until the managers reaches the maximum number of log files, which will cause the oldest existsing log file to be removed.

Returns:
The maximum number of log files

log

public void log(java.lang.String message)
         throws java.io.IOException
Write a message to the log. The message that ends up on the log will have the following form:

TT:MM:SS - message

For example

12:04:58 - A game object was created

Specified by:
log in interface IpLogManager
Parameters:
message - The message to write to the log
Throws:
java.io.IOException - If an IO exception occurs while writing the message