com.sap.tc.logging
Class FileLog

java.lang.Object
  |
  +--com.sap.tc.logging.ExceptionHandling
        |
        +--com.sap.tc.logging.Log
              |
              +--com.sap.tc.logging.StreamLog
                    |
                    +--com.sap.tc.logging.FileLog
All Implemented Interfaces:
java.lang.Cloneable, IFileLog, ILog, IObjectInfo
Direct Known Subclasses:
ReadableLog

public class FileLog
extends StreamLog
implements IFileLog

Writes log records to files.


Field Summary
static int DEF_LIMIT
           
static int MODE_FILE_SET
           
static int MODE_MAX
           
static int MODE_MIN
           
static int MODE_SINGLE_FILE
           
static int NO_CNT
           
static int NO_LIMIT
           
 
Fields inherited from class com.sap.tc.logging.Log
LOG_ACCESSABILITY_TYPE_LOCAL_LOG, LOG_ACCESSABILITY_TYPE_NORMAL_LOG, LOG_ACCESSABILITY_TYPE_PRIVATE_LOG, STATUS_CLOSED, STATUS_INVALID, STATUS_OPENED
 
Constructor Summary
FileLog(java.lang.String pattern)
          Configures this file log for writing to a single file.
FileLog(java.lang.String pattern, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom appending logic.
FileLog(java.lang.String pattern, Formatter formatter)
          Same as FileLog(java.lang.String) but configures for writing with a custom formatter.
FileLog(java.lang.String pattern, Formatter formatter, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom formatter and appending logic.
FileLog(java.lang.String pattern, int limit, int cnt)
          Configures this file log for writing to a rotating set of numbered files.
FileLog(java.lang.String pattern, int limit, int cnt, Formatter formatter)
          Same as FileLog(java.lang.String, int, int) but configures for writing with a custom formatter.
FileLog(java.lang.String pattern, java.lang.String enc)
          Same as FileLog(java.lang.String) but configures for writing with a custom character encoding.
FileLog(java.lang.String pattern, java.lang.String enc, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom character encoding and appending logic.
FileLog(java.lang.String pattern, java.lang.String enc, Formatter formatter)
          Same as FileLog(java.lang.String) but configures for writing with a custom formatter and character encoding.
FileLog(java.lang.String pattern, java.lang.String enc, Formatter formatter, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom character encoding, formatter and appending logic.
FileLog(java.lang.String pattern, java.lang.String enc, int limit, int cnt)
          Same as FileLog(java.lang.String, int, int) but configures for writing with a custom character encoding.
FileLog(java.lang.String pattern, java.lang.String enc, int limit, int cnt, Formatter formatter)
          Same as FileLog(java.lang.String, int, int) but configures for writing with a custom formatter and character encoding.
 
Method Summary
 java.util.List calculateFileNames()
           
static java.util.Collection calculateFileNames(java.lang.String filePattern, int fileCount)
           
 boolean equals(java.lang.Object object)
           
 java.lang.String findBeginningOfFileSet()
          Returns the pathname string of the file from the file set, where the first (oldest) message was written.
 java.lang.String findEndOfFileSet()
          Returns the pathname string of the file from the file set, where the last (newest) message was written.
 int getCnt()
          Gets the max count number of rotating fileset
 java.lang.String getFileCurrentlyBeingWritten()
          Deprecated. Same as getFileName()
 long getFileLength()
          Returns the length of the file(s).
 java.lang.String getFileName()
          Deprecated. A current return value is equal to the java.io.File.getPath() (path name) but from the name of the method java.io.File.getName() (file name) is expected. Please use the FileLog.getPath() for getting a path name value, and the java.io.File.getName() for getting a file name value.
 java.lang.String getFileNamePattern()
           
 java.lang.String getFilePathPattern()
           
 int getIndex()
          Gets the current file index in the rotating file set
 int getLimit()
          Gets the limit file size used for sequencing on the rotating output file
 java.lang.String getLogId()
          Deprecated. Same as getPattern()
 int getMode()
          Get current working mode of the FileLog return 0 == FileLog.MODE_FILE_SET 1 == FileLog.MODE_SINGLE_FILE
 java.lang.String getParent()
          Returns the pathname string of this FileLog object's pattern's parent, or null if the pattern does not expand to a pathname that has a parent directory.
 java.io.File getParentFile()
          Deprecated. Use new java.io.File(FileLog.getParent())
 java.lang.String getPath()
          Returns the pathname string of the current file this FileLog object represent.
 java.lang.String getPattern()
          Gets the file name pattern of this file log.
 boolean isAppend()
          Checks whether this file log writes messages to the end of the specified file rather than the beginning.
 void setFormatter(Formatter formatter)
          Sets the formatter that dictates the format of log records in this log.
 void setMode(int mode)
          Set current working mode of the FileLog mode 0 == FileLog.MODE_FILE_SET 1 == FileLog.MODE_SINGLE_FILE
 void setRotation(int limit, int cnt)
          Set the max count number of rotating fileset and set the limit file size used for sequencing on the rotating output file This may change behaviour of the curent rotating fileset in a way: - Setting an incompatible value to the count or the limit will kill the rotating file set.
 
Methods inherited from class com.sap.tc.logging.StreamLog
getEncoding, setEncoding
 
Methods inherited from class com.sap.tc.logging.Log
addFilter, beGroup, beLogged, close, flush, getDescription, getEffectiveSeverity, getFilters, getFooter, getFormatter, getHeader, getLoggedCount, getLogName, getLogTypeAccessibility, getName, getNumberOfLogRecordsWritten, getOwners, getRecord, getVerInUse, isAutoFlush, isClosed, isFiltersAgreeing, isOpened, isSuppressing, open, removeFilter, removeFilters, reset, resetLoggedCount, setAutoFlush, setDescription, setEffectiveSeverity, setLogName, setLogTypeAccessibility, setName, setSuppressing, size, status, write
 
Methods inherited from class com.sap.tc.logging.ExceptionHandling
getException, getExceptions, handleException, handleException, resetException, throwException
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sap.tc.logging.interfaces.ILog
addFilter, beLogged, close, flush, getEffectiveSeverity, getEncoding, getFilters, getFooter, getFormatter, getHeader, getLogTypeAccessibility, getNumberOfLogRecordsWritten, isAutoFlush, isClosed, isOpened, open, removeFilter, removeFilters, setAutoFlush, setEffectiveSeverity, setEncoding, setLogTypeAccessibility, status
 
Methods inherited from interface com.sap.tc.logging.interfaces.IObjectInfo
getDescription, getName, getVerInUse
 

Field Detail

DEF_LIMIT

public static final int DEF_LIMIT

NO_LIMIT

public static final int NO_LIMIT

NO_CNT

public static final int NO_CNT

MODE_MIN

public static final int MODE_MIN

MODE_SINGLE_FILE

public static final int MODE_SINGLE_FILE

MODE_FILE_SET

public static final int MODE_FILE_SET

MODE_MAX

public static final int MODE_MAX
Constructor Detail

FileLog

public FileLog(java.lang.String pattern)
Configures this file log for writing to a single file. The name of the file can be given using a pattern with a number of place holders: If the file exists messages are append to the end of the file.
Parameters:
pattern - File name pattern
See Also:
FileLog(java.lang.String, int, int)

FileLog

public FileLog(java.lang.String pattern,
               boolean append)
Same as FileLog(java.lang.String) but configures for writing with a custom appending logic. If the specified file exists but the second argument is false file content will be deleted before writing.
Parameters:
pattern - File name pattern
append - If false file content will be deleted before writing

FileLog

public FileLog(java.lang.String pattern,
               Formatter formatter)
Same as FileLog(java.lang.String) but configures for writing with a custom formatter.
Parameters:
pattern - File name pattern
formatter - Formatter
See Also:
FileLog(java.lang.String, int, int, Formatter)

FileLog

public FileLog(java.lang.String pattern,
               Formatter formatter,
               boolean append)
Same as FileLog(java.lang.String) but configures for writing with a custom formatter and appending logic. If the specified file exists but the third argument is false file content will be deleted before writing.
Parameters:
pattern - File name pattern
formatter - Formatter
append - If false file content will be deleted before writing

FileLog

public FileLog(java.lang.String pattern,
               java.lang.String enc)
        throws java.io.UnsupportedEncodingException
Same as FileLog(java.lang.String) but configures for writing with a custom character encoding.
Parameters:
pattern - File name pattern
enc - Name of character encoding
Throws:
java.io.UnsupportedEncodingException - Character encoding not supported
See Also:
FileLog(java.lang.String, java.lang.String, int, int)

FileLog

public FileLog(java.lang.String pattern,
               java.lang.String enc,
               boolean append)
        throws java.io.UnsupportedEncodingException
Same as FileLog(java.lang.String) but configures for writing with a custom character encoding and appending logic. If the specified file exists but the third argument is false file content will be deleted before writing.
Parameters:
pattern - File name pattern
enc - Name of character encoding
append - If false file content will be deleted before writing
Throws:
java.io.UnsupportedEncodingException - Character encoding not supported

FileLog

public FileLog(java.lang.String pattern,
               java.lang.String enc,
               Formatter formatter)
        throws java.io.UnsupportedEncodingException
Same as FileLog(java.lang.String) but configures for writing with a custom formatter and character encoding.
Parameters:
pattern - File name pattern
enc - Name of character encoding
formatter - Formatter
Throws:
java.io.UnsupportedEncodingException - Character encoding not supported
See Also:
FileLog(java.lang.String, java.lang.String, int, int)

FileLog

public FileLog(java.lang.String pattern,
               java.lang.String enc,
               Formatter formatter,
               boolean append)
        throws java.io.UnsupportedEncodingException
Same as FileLog(java.lang.String) but configures for writing with a custom character encoding, formatter and appending logic. If the specified file exists but the fourth argument is false file content will be deleted before writing.
Parameters:
pattern - File name pattern
enc - Name of character encoding
formatter - Formatter
append - If false file content will be deleted before writing
Throws:
java.io.UnsupportedEncodingException - Character encoding not supported

FileLog

public FileLog(java.lang.String pattern,
               int limit,
               int cnt)
Configures this file log for writing to a rotating set of numbered files. Each file has a limit on its size, and there is a maximum number of files in the set. In addition to the placeholders supported by the single file constructor, %g can be used in the pattern where the number of the file is supposed to go.
Parameters:
pattern - File name pattern
limit - Limit of file sizes in byte or DEF_LIMIT
cnt - Maximum number of files in set or NO_CNT
Throws:
java.lang.IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String)

FileLog

public FileLog(java.lang.String pattern,
               int limit,
               int cnt,
               Formatter formatter)
Same as FileLog(java.lang.String, int, int) but configures for writing with a custom formatter.
Parameters:
pattern - File name pattern
limit - Limit of file sizes in byte or DEF_LIMIT
cnt - Maximum number of files in set or NO_CNT
formatter - Formatter
Throws:
java.lang.IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String, Formatter)

FileLog

public FileLog(java.lang.String pattern,
               java.lang.String enc,
               int limit,
               int cnt)
        throws java.io.UnsupportedEncodingException
Same as FileLog(java.lang.String, int, int) but configures for writing with a custom character encoding.
Parameters:
pattern - File name pattern
enc - Name of character encoding
limit - Limit of file sizes in byte or DEF_LIMIT
cnt - Maximum number of files in set or NO_CNT
Throws:
java.io.UnsupportedEncodingException - Character encoding not supported
java.lang.IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String, java.lang.String, int, int)

FileLog

public FileLog(java.lang.String pattern,
               java.lang.String enc,
               int limit,
               int cnt,
               Formatter formatter)
        throws java.io.UnsupportedEncodingException
Same as FileLog(java.lang.String, int, int) but configures for writing with a custom formatter and character encoding.
Parameters:
pattern - File name pattern
enc - Name of character encoding
limit - Limit of file sizes in byte or DEF_LIMIT
cnt - Maximum number of files in set or NO_CNT
formatter - Formatter
Throws:
java.io.UnsupportedEncodingException - Character encoding not supported
java.lang.IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String, java.lang.String, int, int)
Method Detail

getMode

public int getMode()
Get current working mode of the FileLog return 0 == FileLog.MODE_FILE_SET 1 == FileLog.MODE_SINGLE_FILE

setMode

public void setMode(int mode)
Set current working mode of the FileLog mode 0 == FileLog.MODE_FILE_SET 1 == FileLog.MODE_SINGLE_FILE

setFormatter

public void setFormatter(Formatter formatter)
Sets the formatter that dictates the format of log records in this log. Note: If you send a null like argument the default formater (ListFormatter), will be created.
Specified by:
setFormatter in interface ILog
Overrides:
setFormatter in class Log
Returns:
Formatter
See Also:
Log.getFormatter()

calculateFileNames

public java.util.List calculateFileNames()

calculateFileNames

public static java.util.Collection calculateFileNames(java.lang.String filePattern,
                                                      int fileCount)

getFileLength

public long getFileLength()
Returns the length of the file(s).
Specified by:
getFileLength in interface IFileLog
Returns:
the length of this file, measured in bytes.
Throws:
java.io.IOException - if an I/O error occurs.

getPath

public java.lang.String getPath()
Returns the pathname string of the current file this FileLog object represent.
Specified by:
getPath in interface IFileLog
Returns:
The pathname

getParent

public java.lang.String getParent()
Returns the pathname string of this FileLog object's pattern's parent, or null if the pattern does not expand to a pathname that has a parent directory.
Specified by:
getParent in interface IFileLog
Returns:
The parent pathname

getPattern

public java.lang.String getPattern()
Gets the file name pattern of this file log.
Specified by:
getPattern in interface IFileLog
Returns:
File name pattern

getFilePathPattern

public java.lang.String getFilePathPattern()

getFileNamePattern

public java.lang.String getFileNamePattern()

getLimit

public int getLimit()
Gets the limit file size used for sequencing on the rotating output file
Specified by:
getLimit in interface IFileLog
Returns:
Limit file size

getCnt

public int getCnt()
Gets the max count number of rotating fileset
Specified by:
getCnt in interface IFileLog
Returns:
Number of files in rotating fileset.

getIndex

public int getIndex()
Gets the current file index in the rotating file set
Returns:
Limit file size

setRotation

public void setRotation(int limit,
                        int cnt)
Set the max count number of rotating fileset and set the limit file size used for sequencing on the rotating output file This may change behaviour of the curent rotating fileset in a way: - Setting an incompatible value to the count or the limit will kill the rotating file set. Possible incompatibilities are: count <= 0 or/and limit <= 0 - Set FileLog mode to MODE_FILE_SET - All changes are active immediately on a newly created file!

isAppend

public boolean isAppend()
Checks whether this file log writes messages to the end of the specified file rather than the beginning.
Specified by:
isAppend in interface IFileLog
Returns:
true if and only if this file log writes messages to the end of the specified file rather than the beginning

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

findBeginningOfFileSet

public java.lang.String findBeginningOfFileSet()
Returns the pathname string of the file from the file set, where the first (oldest) message was written.
Returns:
The pathname

findEndOfFileSet

public java.lang.String findEndOfFileSet()
Returns the pathname string of the file from the file set, where the last (newest) message was written.
Returns:
The pathname

getFileName

public java.lang.String getFileName()
Deprecated. A current return value is equal to the java.io.File.getPath() (path name) but from the name of the method java.io.File.getName() (file name) is expected. Please use the FileLog.getPath() for getting a path name value, and the java.io.File.getName() for getting a file name value.

Same like FileLog.getPath() Cann be null;
Specified by:
getFileName in interface IFileLog
Returns:
FileLog.getPath()

getFileCurrentlyBeingWritten

public java.lang.String getFileCurrentlyBeingWritten()
Deprecated. Same as getFileName()


getParentFile

public java.io.File getParentFile()
Deprecated. Use new java.io.File(FileLog.getParent())


getLogId

public java.lang.String getLogId()
Deprecated. Same as getPattern()