com.sap.tc.logging

Class FileLog

java.lang.Object
  extended by com.sap.tc.logging.ExceptionHandling
      extended by com.sap.tc.logging.Log
          extended by com.sap.tc.logging.StreamLog
              extended by com.sap.tc.logging.FileLog
All Implemented Interfaces:
IFileLog, ILog, IObjectInfo, Cloneable

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
 
Fields inherited from class com.sap.tc.logging.ExceptionHandling
EX_NO_FILTER_EMSG, EX_NO_FORMATTER_EMSG, EX_NO_INSTANCE_EMSG
 
Constructor Summary
protected FileLog()
           
  FileLog(String pattern)
          Configures this file log for writing to a single file.
  FileLog(String pattern, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom appending logic.
  FileLog(String pattern, Formatter formatter)
          Same as FileLog(java.lang.String) but configures for writing with a custom formatter.
  FileLog(String pattern, Formatter formatter, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom formatter and appending logic.
  FileLog(String pattern, int limit, int cnt)
          Configures this file log for writing to a rotating set of numbered files.
  FileLog(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(String pattern, String enc)
          Same as FileLog(java.lang.String) but configures for writing with a custom character encoding.
  FileLog(String pattern, String enc, boolean append)
          Same as FileLog(java.lang.String) but configures for writing with a custom character encoding and appending logic.
  FileLog(String pattern, String enc, Formatter formatter)
          Same as FileLog(java.lang.String) but configures for writing with a custom formatter and character encoding.
  FileLog(String pattern, 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(String pattern, String enc, int limit, int cnt)
          Same as FileLog(java.lang.String, int, int) but configures for writing with a custom character encoding.
  FileLog(String pattern, 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
 List calculateFileNames()
           
static Collection calculateFileNames(String filePattern, int fileCount)
           
protected  Object clone()
           
 boolean equals(Object object)
           
protected  boolean equalsPattern(String pattern, boolean onlyNewFormat)
           
protected  String expandPattern(boolean onlyNewFormat)
           
protected  String expandPattern(int fileIndex, boolean onlyNewFormat)
           
protected  String expandPattern(String filePattern, int fileCount, boolean isRotate, boolean onlyNewFormat)
           
 String findBeginningOfFileSet()
          Returns the pathname string of the file from the file set, where the first (oldest) message was written.
 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
 String getFileCurrentlyBeingWritten()
          Deprecated. Same as getFileName()
 long getFileLength()
          Returns the length of the file(s).
 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.
 String getFileNamePattern()
           
 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
 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
 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.
 File getParentFile()
          Deprecated. Use new java.io.File(FileLog.getParent())
 String getPath()
          Returns the pathname string of the current file this FileLog object represent.
 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.
protected  void resetInt()
          Reset all current FileLog settings and starts from beginning Current file
protected  void setAppend(boolean append)
           
protected  void setCnt(int value)
           
 void setFormatter(Formatter formatter)
          Sets the formatter that dictates the format of log records in this log.
protected  void setFormatterInt(Formatter formatter)
           
protected  void setIndex(int value)
           
protected  void setLimit(int value)
           
 void setMode(int mode)
          Set current working mode of the FileLog mode 0 == FileLog.MODE_FILE_SET 1 == FileLog.MODE_SINGLE_FILE
protected  void setPattern(String pattern)
           
 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.
protected  void writeInt(String s)
           Writes a log message string to this log.
protected  void writeLogFooter()
          Writes a log footer to this log.
protected  void writeLogHeader()
          Writes a log header to this log.
 
Methods inherited from class com.sap.tc.logging.StreamLog
closeInt, flushInt, getEncoding, getOutputStream, openInt, setEncoding
 
Methods inherited from class com.sap.tc.logging.Log
addFilter, addOwner, beGroup, beLogged, close, finalize, flush, getDescription, getEffectiveSeverity, getFilters, getFooter, getFormatter, getHeader, getLocalLogOwner, getLoggedCount, getLogName, getLogTypeAccessibility, getName, getNumberOfLogRecordsWritten, getOwners, getRecord, getVerInUse, isAutoFlush, isClosed, isFiltersAgreeing, isHeaderWritten, isOpened, isSuppressing, open, removeFilter, removeFilters, removeOwner, reset, resetLoggedCount, setAutoFlush, setDescription, setEffectiveSeverity, setFooter, setHeader, setHeaderWritten, setLocalLogOwner, setLogName, setLogTypeAccessibility, setName, setSize, setStatus, setSuppressing, setVerInUse, size, status, write, writeInt
 
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
See Also:
Constant Field Values

NO_LIMIT

public static final int NO_LIMIT
See Also:
Constant Field Values

NO_CNT

public static final int NO_CNT
See Also:
Constant Field Values

MODE_MIN

public static final int MODE_MIN
See Also:
Constant Field Values

MODE_SINGLE_FILE

public static final int MODE_SINGLE_FILE
See Also:
Constant Field Values

MODE_FILE_SET

public static final int MODE_FILE_SET
See Also:
Constant Field Values

MODE_MAX

public static final int MODE_MAX
See Also:
Constant Field Values
Constructor Detail

FileLog

public FileLog(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(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(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(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(String pattern,
               String enc)
        throws 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:
UnsupportedEncodingException - Character encoding not supported
See Also:
FileLog(java.lang.String, java.lang.String, int, int)

FileLog

public FileLog(String pattern,
               String enc,
               boolean append)
        throws 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:
UnsupportedEncodingException - Character encoding not supported

FileLog

public FileLog(String pattern,
               String enc,
               Formatter formatter)
        throws 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:
UnsupportedEncodingException - Character encoding not supported
See Also:
FileLog(java.lang.String, java.lang.String, int, int)

FileLog

public FileLog(String pattern,
               String enc,
               Formatter formatter,
               boolean append)
        throws 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:
UnsupportedEncodingException - Character encoding not supported

FileLog

public FileLog(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:
IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String)

FileLog

public FileLog(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:
IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String, Formatter)

FileLog

public FileLog(String pattern,
               String enc,
               int limit,
               int cnt)
        throws 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:
UnsupportedEncodingException - Character encoding not supported
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(String pattern,
               String enc,
               int limit,
               int cnt,
               Formatter formatter)
        throws 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:
UnsupportedEncodingException - Character encoding not supported
IllegalArgumentException - Pattern or one, but not both, of limit and cnt unspecified
See Also:
FileLog(java.lang.String, java.lang.String, int, int)

FileLog

protected FileLog()
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
See Also:
Log.getFormatter()

calculateFileNames

public List calculateFileNames()

calculateFileNames

public static Collection calculateFileNames(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:
IOException - if an I/O error occurs.

getPath

public 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 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 String getPattern()
Gets the file name pattern of this file log.

Specified by:
getPattern in interface IFileLog
Returns:
File name pattern

getFilePathPattern

public String getFilePathPattern()

getFileNamePattern

public 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(Object object)
Overrides:
equals in class Object

findBeginningOfFileSet

public 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 String findEndOfFileSet()
Returns the pathname string of the file from the file set, where the last (newest) message was written.

Returns:
The pathname

setFormatterInt

protected void setFormatterInt(Formatter formatter)

resetInt

protected void resetInt()
Reset all current FileLog settings and starts from beginning Current file

Overrides:
resetInt in class Log

clone

protected Object clone()
                throws CloneNotSupportedException
Overrides:
clone in class StreamLog
Throws:
CloneNotSupportedException

writeLogHeader

protected void writeLogHeader()
Description copied from class: Log
Writes a log header to this log.

Overrides:
writeLogHeader in class Log

writeLogFooter

protected void writeLogFooter()
Description copied from class: Log
Writes a log footer to this log.

Overrides:
writeLogFooter in class Log

writeInt

protected void writeInt(String s)
                 throws Exception
Description copied from class: Log

Writes a log message string to this log. This method is meant as the standard way of implementing the fashion in which a log message is written to its destination. Note that this method is called inside a synchronized statement that locks this log, in order to avoid deadlocks.

If you need access to the log record to be written you should override Log.writeInt(java.lang.String). Note that, nevertheless, even in this case it is usually necessary to reimplement this method.

Overrides:
writeInt in class StreamLog
Throws:
IOException - Exception from writing messages to the destination
Exception

equalsPattern

protected boolean equalsPattern(String pattern,
                                boolean onlyNewFormat)

expandPattern

protected String expandPattern(boolean onlyNewFormat)

expandPattern

protected String expandPattern(int fileIndex,
                               boolean onlyNewFormat)

setIndex

protected void setIndex(int value)

setCnt

protected void setCnt(int value)

setLimit

protected void setLimit(int value)

setPattern

protected void setPattern(String pattern)

setAppend

protected void setAppend(boolean append)

expandPattern

protected String expandPattern(String filePattern,
                               int fileCount,
                               boolean isRotate,
                               boolean onlyNewFormat)

getFileName

public 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 String getFileCurrentlyBeingWritten()
Deprecated. Same as getFileName()


getParentFile

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


getLogId

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

Access Rights

This class can be accessed from:


SC DC
[sap.com] FRAMEWORK [sap.com] tc/ddic/ddicruntime
[sap.com] ENGINEAPI [sap.com] tc/logging
[sap.com] ENGFACADE [sap.com] tc/bl/logging/api
[sap.com] CORE-TOOLS [sap.com] com.sap.engine.client.lib
[sap.com] BRMS-FACADE [sap.com] tc/brms/facade


Copyright 2010 SAP AG Complete Copyright Notice