com.adventnet.afp.log
Class FileLogWriter

java.lang.Object
  |
  +--com.adventnet.afp.log.AbstractLogWriter
        |
        +--com.adventnet.afp.log.FileLogWriter
All Implemented Interfaces:
LogWriter

public class FileLogWriter
extends AbstractLogWriter

FilelogWriter is a default implementation of the LogWriter provided by the Logging  Framework. As the name implies, the FilelogWriter redirects all the log out and log error messages to the corresponding files. When the number of lines in the file in
current use reaches the maximum number specified in the configuration, the FilelogWriter automatically opens a new file and all further log messages will be written into it and so on.

By default, the FilelogWriter prescribes names for the file in current use and for all further files. The file in current use will be named always as serverout.txt or servererr.txt. The name for the previous files, will be in incremented order. For example, supposing the FilelogWriter has created 5 files and the 6th one is the current file, then, the fifth file will bear the name serverout1.txt, the fourth file will have the name serverout2.txt and so on.

All the new files will have the label "LOG_STARTED_STR" on their top. If a new file is the continuation of the previous one, it will bear the label "LOG_CONTINUED_STR" on its top.

Whenever the number of files reaches the maximum prescribed limit in the configuration , the oldest file (in other words, the first generated file) is moved to the Archives. For example, the default value for the parameter MaxFileCount is set as 10. Upon
reaching this maximum count, when the 11th file is created, the first one is moved to the Archives. When there arises a need to refer to the first file, you may visit the Archives and pick that file.

Buffering can be done in two modes - Auto or Manual. The custom properties are file name, maximum line count, maximum
file count , Buffer size,Flush mode, Logs directory, Archive directory and; Archive status.  The key names for all the Custom properties are FileName,MaxLineCount,MaxFileCount,BufferSize,FlushMode, LogsDirectory,ArchiveDirectory and ArchiveStatus. The user can give their own property under the Property tag similar to the properties mentioned  above.(FileName,MaxLineCount etc) which are considered to be as custom properties.


Fields inherited from class com.adventnet.afp.log.AbstractLogWriter
listeners
 
Constructor Summary
FileLogWriter()
          Creates a new FileLogWriter instance.
 
Method Summary
 boolean archiveFile(java.lang.String sourceZipFile, java.lang.String fileName)
          The file before getting deleted from the logs directory, is moved to Archive.
 void close()
          This method will close the stream that are opened and releases any resources that are associated with the stream.
 void err(java.lang.String message, java.lang.Throwable exception)
          Prints this Throwable exception and its error message to the log file.When the error messages and the Throwable is passed to this method, the messages and stack trace belonging to it will be printed into the file.
 void flush()
          This method transfers the logout and logerror messages from memory in to the file and cleans the memory area.
 java.lang.String getArchiveDirectory()
          This will return the Archive directory.The Archive directory mentioned in the logging configuration file will be returned.
 boolean getArchiveStatus()
          This will return the Archive status.The current Archive status will be retreived.
 int getBufferSize()
          The buffer size is retreived.Since the buffer size can be changed at runtime, this method returns the currently modified size of the buffer.
 java.lang.String getFileName()
          This will return the log file name .
 java.lang.String getFlushMode()
          Used to get the flush mode on which this instance is operating.
 java.lang.String getLogDirectory()
          This will return the log directory.
 int getMaxFileCount()
          This will return the maximum file count.
 int getMaxLineCount()
          This will return the maximum lines .The maximum number of lines per file that is used currently can be retreived using this method.
 void init(LogWriterProperties prop)
          For initializing implementation class with required properties.
 void out(java.lang.String message)
          This method writes the log messages to the current file.
 void setArchiveStatus(boolean archiveStatus)
          This will Set the archive status at runtime.If the status is true , then deleted file will be moved to the archive else it will not be moved to archive.
 void setBufferSize(int size)
          The buffer size is set for the corresponding buffer type .
 void setFlushMode(java.lang.String type)
          This will set the flush mode at runtime.
 void setMaxFileCount(int no)
          This will Set the maximum file count at runtime.The maximum number of files of same type under the logs directory mentioned in the logging configuration file can be changed at runtime by setting the number of lines using this method.
 void setMaxLineCount(int no)
          This will Set the maximum line count at runtime.The maximum number of lines per file mentioned in the logging configuration file can be changed at runtime by setting the number of lines using this method.
 
Methods inherited from class com.adventnet.afp.log.AbstractLogWriter
addPropertyChangeListener, getInstanceName, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLogWriter

public FileLogWriter()
Creates a new FileLogWriter instance.
Method Detail

init

public void init(LogWriterProperties prop)
          throws LogException
For initializing implementation class with required properties. The Properties are taken from the logging configuration file. If the properties are null, then the default properties will be taken for the Logging operation.
Overrides:
init in class AbstractLogWriter
Parameters:
prop - Properties containing information read from the logging configuration file.
Throws:
LogException - if an error occurs during initialization

archiveFile

public boolean archiveFile(java.lang.String sourceZipFile,
                           java.lang.String fileName)
The file before getting deleted from the logs directory, is moved to Archive. When the Maximum file count is reached, the older files gets deleted. In order to keep track of all the log files,the file is moved to the Archive before getting deleted.
Parameters:
sourceZipFile - The zip file where the files are stored.
fileName - The file which will be moved to Archive before getting deleted.
Returns:
Return True when the files are moved to Archive else false.

out

public void out(java.lang.String message)
This method writes the log messages to the current file. If buffering is enabled ( when bufferSize>0 ), the log messages are stored in the memory. Upon reaching the maximum number of lines ( which is specified in the logging configuration file flush() method is called .
Parameters:
message - A string to be logged.

err

public void err(java.lang.String message,
                java.lang.Throwable exception)
Prints this Throwable exception and its error message to the log file.When the error messages and the Throwable is passed to this method, the messages and stack trace belonging to it will be printed into the file. The buffering is enabled(i.e.when bufferSize>0) for the error messages also. Thus the Line count is maintained in the file.
Parameters:
exception - Throwable
message - Error message to be logged.

flush

public void flush()
           throws LogException
This method transfers the logout and logerror messages from memory in to the file and cleans the memory area. The maximum number of lines that can be stored in the memory can be specified in the logging configuration file
Throws:
LogException - if an error occurs while flushing the contents of the writer

close

public void close()
           throws LogException
This method will close the stream that are opened and releases any resources that are associated with the stream.
Throws:
LogException - if an error occurs while closing the writer

setFlushMode

public void setFlushMode(java.lang.String type)
This will set the flush mode at runtime. Depending upon the mode, the flushing operation differs. It can be either Auto or Manual. When this method is invoked with the argument as invalid or some value other than Auto or Manual , then the FlushMode is taken as Auto. In this mode,the messages will be collected in the buffer and when it reaches the buffer size, all the messages in the buffer will be flushed into their respective files. Another option is Manual where the messages will be collected in the buffer until the flush method is invoked by the user. When the messages in the buffer reaches the buffer size the old messages will be overwritten. Thus in this buffering, the messages will not exceed the buffersize.
Parameters:
type - Type of buffering either "Auto" or "Manual"

getFlushMode

public java.lang.String getFlushMode()
Used to get the flush mode on which this instance is operating. Possible return values are "Auto" and "Manual"
Returns:
Returns the flush mode as a String

setBufferSize

public void setBufferSize(int size)
The buffer size is set for the corresponding buffer type . If the BufferSize is greater than 0, the buffering is enabled.The size of the buffer can be changed at runtime with this method. By default the buffer size is given as 0. Whatever be the type of buffering , when the buffer size exceeds the value 0, the buffering operation is performed.Depending upon the buffer size, the buffering operation differs for the buffer type.
Parameters:
size - The buffer size for the corresponding buffer type.

getBufferSize

public int getBufferSize()
The buffer size is retreived.Since the buffer size can be changed at runtime, this method returns the currently modified size of the buffer. When the buffer size is not changed at runtime, then the value of buffer size is retreived from the logging configuration file.
Returns:
Returns the buffer size specified for logging.

getFileName

public java.lang.String getFileName()
This will return the log file name . The log file name which was mentioned in the logging configuration file will be returned.
Returns:
Returns the log file name.

getLogDirectory

public java.lang.String getLogDirectory()
This will return the log directory. The logs directory which was mentioned in the logging configuration file will be returned.
Returns:
Returns the log directory name.

getArchiveDirectory

public java.lang.String getArchiveDirectory()
This will return the Archive directory.The Archive directory mentioned in the logging configuration file will be returned.
Returns:
Returns the Archive directory name.

setMaxLineCount

public void setMaxLineCount(int no)
This will Set the maximum line count at runtime.The maximum number of lines per file mentioned in the logging configuration file can be changed at runtime by setting the number of lines using this method.
Parameters:
no - The size of the maximum line count.

getMaxLineCount

public int getMaxLineCount()
This will return the maximum lines .The maximum number of lines per file that is used currently can be retreived using this method.
Returns:
Returns the maximum number of lines that can be used in the log file.

setMaxFileCount

public void setMaxFileCount(int no)
This will Set the maximum file count at runtime.The maximum number of files of same type under the logs directory mentioned in the logging configuration file can be changed at runtime by setting the number of lines using this method.
Parameters:
no - The size of the maximum file count.

getMaxFileCount

public int getMaxFileCount()
This will return the maximum file count. The maximum number of files that can be used currently of same type under logs directory can be retreived using this method.
Returns:
Returns the maximum number of files of the same type under the log directory.

setArchiveStatus

public void setArchiveStatus(boolean archiveStatus)
This will Set the archive status at runtime.If the status is true , then deleted file will be moved to the archive else it will not be moved to archive. The status can be changed at runtime.
Parameters:
archiveStatus - The status of the Archive which is passed as boolean.

getArchiveStatus

public boolean getArchiveStatus()
This will return the Archive status.The current Archive status will be retreived.
Returns:
Returns the Status of the Archive.


Copyright (c)AdventNet Inc., 1996-2004