com.funambol.util
Class FileAppender

java.lang.Object
  extended by com.funambol.util.FileAppender
All Implemented Interfaces:
Appender

public class FileAppender
extends java.lang.Object
implements Appender

This appender logs messages to a file using JSR75 (FileConnection) The appender tracks the file size and if it exceeds a given maximum size (customizable by clients) then the current log file is renamed appending a .old to the log name and a new one is created. Therefore the maximum size on this is about 2 times the maxFileSize (this is not accurate as there is no limit on the size of the single message printed).


Constructor Summary
FileAppender(java.lang.String path, java.lang.String fileName)
          Default constructor
 
Method Summary
 void closeLogFile()
          Close connection and streams
 void deleteLogFile()
          Delete the log file
 LogContent getLogContent()
          Get the whole log content for this appender
 void initLogFile()
          Init the logger
 void openLogFile()
          FileAppender doesn't implement this method
 void setContentPath(java.lang.String path)
          Sets the content path.
 void setLogContentType(boolean memory)
          Sets the content type of the log when it is retrieved via getLogContent.
 void setLogLevel(int level)
          Perform additional actions needed when setting a new level.
 void setMaxFileSize(long maxFileSize)
          Sets the maximum file size.
 void writeLogMessage(java.lang.String level, java.lang.String msg)
          FileAppender writes one message to the output file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileAppender

public FileAppender(java.lang.String path,
                    java.lang.String fileName)
Default constructor

Method Detail

setMaxFileSize

public void setMaxFileSize(long maxFileSize)
Sets the maximum file size. Once this is size is reached, the current log file is renamed and a new one is created. This way we have at most 2 log files whose size is (roughly) bound to maxFileSize. The minimum file size is 1024 as smaller size does not really make sense. If a client needs smaller files it should probably the usage of other Appenders or modify the behavior of this one by deriving it.

Parameters:
maxFileSize - the max size in bytes

setContentPath

public void setContentPath(java.lang.String path)
Sets the content path. This path is the directory where the combined log is placed so that the LogContent is accessible. By default this directory is the same as the log directory, but it is possible to specify a different one if needed.


setLogContentType

public void setLogContentType(boolean memory)
Sets the content type of the log when it is retrieved via getLogContent. By default the FileAppender returns a content in a file, but if the client prefers an inlined value, then this method allows to force this behavior. Note that regardless of this setting, the log is always written to a file.


writeLogMessage

public void writeLogMessage(java.lang.String level,
                            java.lang.String msg)
FileAppender writes one message to the output file

Specified by:
writeLogMessage in interface Appender

initLogFile

public void initLogFile()
Init the logger

Specified by:
initLogFile in interface Appender

openLogFile

public void openLogFile()
FileAppender doesn't implement this method

Specified by:
openLogFile in interface Appender

closeLogFile

public void closeLogFile()
Close connection and streams

Specified by:
closeLogFile in interface Appender

setLogLevel

public void setLogLevel(int level)
Perform additional actions needed when setting a new level. FileAppender doesn't implement this method

Specified by:
setLogLevel in interface Appender

deleteLogFile

public void deleteLogFile()
Delete the log file

Specified by:
deleteLogFile in interface Appender

getLogContent

public LogContent getLogContent()
                         throws java.io.IOException
Description copied from interface: Appender
Get the whole log content for this appender

Specified by:
getLogContent in interface Appender
Returns:
LogContent the LogContent object log Container
Throws:
java.io.IOException


Copyright © 2001-2009 Funambol.