com.sap.tc.logging.reader
Class ReadableLog

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

public class ReadableLog
extends FileLog
implements IReadableLog

Defines common operations to read log messages (a message record) from a log destination. Currently, this mainly handles sequential records retrieval starting either from the oldest or latest time point. To avoid messing up the sequential reading from concurrent readers on the same log destination, it is recommended to get a copy of this 'readable' log for each reader.


Fields inherited from class com.sap.tc.logging.FileLog
DEF_LIMIT, MODE_FILE_SET, MODE_MAX, MODE_MIN, MODE_SINGLE_FILE, NO_CNT, 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
ReadableLog(java.lang.String pattern)
          Deprecated. ReadableLog become factory class. Use factory methods: - createReadableLog(FileLog fileLog) to get old IReadableLog instance - createFileReadLog(FileLog fileLog) to get new IReadLog instance for reading Files written using ListFormatter and TraceFormatter
 
Method Summary
 boolean areLoggingAttributesEditable()
          This method verifies whether the attributes like severity can be set.
 void close()
          Closes output of this log object.
static IReadLog createFileReadLog(FileLog fileLog)
          Deprecated. Not suported
static IReadLog createFileReadLog(java.lang.String fileName)
          Create FileReadLog object.
 IReadableLog createReadableLog()
          Create a 'copy' of this Filelog, exposing only the message reading API.
static IReadableLog createReadableLog(FileLog fileLog)
          Create a 'copy' of this Filelog, exposing only the message reading API.
static IReadableLog createReadableLog(FileLog fileLog, java.util.Locale locale)
           
 IReadableLog createReadableLog(java.util.Locale locale)
           
 java.lang.String getFileBeingCurrentlyRead()
          This method returns the name of the file that is being currently read.
 long getFilePointer()
          This returns the file pointer.
 long getLastModified()
           
 ILoggingResultSet getNextMatch(java.lang.String[] searchTokens)
          This method returns LoggingResultSet that contains one or zero LogRecords.
 ILoggingResultSet getNextMatch(java.lang.String[] searchTokens, boolean ignoreCase)
          This method returns LoggingResultSet that contains one or zero LogRecords.
 ILoggingResultSet getPreviousMatch(java.lang.String[] searchTokens)
          This method returns LoggingResultSet that contains one or zero LogRecords.
 ILoggingResultSet getPreviousMatch(java.lang.String[] searchTokens, boolean ignoreCase)
          This method returns LoggingResultSet that contains one or zero LogRecords.
 long length()
          Deprecated. Use getFileLenght()
 void open()
          Closes output of this log object.
 ILoggingResultSet readLatestMsgRecords(int numberOfRecords)
           Retrieve the latest n messages and return them in a result set in chronological order.
 java.util.ArrayList readLatestRecords(int numMsg)
          Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readLatestMsgRecords(int).
 ILoggingResultSet readNextMsgRecords(int numberOfRecords)
           Continue retrieving x relatively newer messages, picked from the point where the last message read from the previous read operation, with respect to the direction of the previous read operation.
 java.util.ArrayList readNextRecords(int numMsg)
          Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readNextMsgRecords(int).
 ILoggingResultSet readOldestMsgRecords(int numberOfRecords)
           Retrieve the oldest n messages and return them in a result set in chronological order.
 java.util.ArrayList readOldestRecords(int numMsg)
          Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readOldestMsgRecords(int).
 ILoggingResultSet readPrevMsgRecords(int numberOfRecords)
           Continue retrieving x relatively older messages, picked from the point where the last message read from the previous read operation, with respect to the direction of the previous read operation.
 java.util.ArrayList readPrevRecords(int numMsg)
          Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readPrevMsgRecords(int).
 void seek(long filePointer)
          Tries to set the file pointer specified by the parameter.
 void setFormatter(Formatter formatter)
          Sets the formatter that dictates the format of log records in this log.
 int status()
          Status of this log object.
 
Methods inherited from class com.sap.tc.logging.FileLog
calculateFileNames, calculateFileNames, equals, findBeginningOfFileSet, findEndOfFileSet, getCnt, getFileCurrentlyBeingWritten, getFileLength, getFileName, getFileNamePattern, getFilePathPattern, getIndex, getLimit, getLogId, getMode, getParent, getParentFile, getPath, getPattern, isAppend, setMode, setRotation
 
Methods inherited from class com.sap.tc.logging.StreamLog
getEncoding, setEncoding
 
Methods inherited from class com.sap.tc.logging.Log
addFilter, beGroup, beLogged, flush, getDescription, getEffectiveSeverity, getFilters, getFooter, getFormatter, getHeader, getLoggedCount, getLogName, getLogTypeAccessibility, getName, getNumberOfLogRecordsWritten, getOwners, getRecord, getVerInUse, isAutoFlush, isClosed, isFiltersAgreeing, isOpened, isSuppressing, removeFilter, removeFilters, reset, resetLoggedCount, setAutoFlush, setDescription, setEffectiveSeverity, setLogName, setLogTypeAccessibility, setName, setSuppressing, size, 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.IReadableLog
getLogId
 
Methods inherited from interface com.sap.tc.logging.interfaces.IFileLog
getCnt, getFileLength, getFileName, getLimit, getParent, getPath, getPattern, isAppend
 
Methods inherited from interface com.sap.tc.logging.interfaces.ILog
addFilter, beLogged, flush, getEffectiveSeverity, getEncoding, getFilters, getFooter, getFormatter, getHeader, getLogTypeAccessibility, getNumberOfLogRecordsWritten, isAutoFlush, isClosed, isOpened, removeFilter, removeFilters, setAutoFlush, setEffectiveSeverity, setEncoding, setLogTypeAccessibility
 
Methods inherited from interface com.sap.tc.logging.interfaces.IObjectInfo
getDescription, getName, getVerInUse
 

Constructor Detail

ReadableLog

public ReadableLog(java.lang.String pattern)
Deprecated. ReadableLog become factory class. Use factory methods: - createReadableLog(FileLog fileLog) to get old IReadableLog instance - createFileReadLog(FileLog fileLog) to get new IReadLog instance for reading Files written using ListFormatter and TraceFormatter

Method Detail

createFileReadLog

public static IReadLog createFileReadLog(FileLog fileLog)
Deprecated. Not suported

This method log all exception but doesn't re-throw it out.

createFileReadLog

public static IReadLog createFileReadLog(java.lang.String fileName)
                                  throws FileDataException
Create FileReadLog object. Note: This method may be used only on log files which contains the file log header data.
Parameters:
fileName -  
Returns:
Instance of FileReadLog
Throws:
FileDataException -  

createReadableLog

public static IReadableLog createReadableLog(FileLog fileLog)
Create a 'copy' of this Filelog, exposing only the message reading API. Then, retrieval of message records for each reader will be independent. This can avoid messing up the sequential reading pointers from potential concurrent multiple readers.
Returns:
A copy of this readable log that contains mainly cursor actions or a null value if creation fails

createReadableLog

public static IReadableLog createReadableLog(FileLog fileLog,
                                             java.util.Locale locale)

createReadableLog

public IReadableLog createReadableLog()
Create a 'copy' of this Filelog, exposing only the message reading API. Then, retrieval of message records for each reader will be independent. This can avoid messing up the sequential reading pointers from potential concurrent multiple readers.
Specified by:
createReadableLog in interface IReadableLog
Returns:
A copy of this readable log that contains mainly cursor actions or a null value if creation fails

createReadableLog

public IReadableLog createReadableLog(java.util.Locale locale)

readLatestMsgRecords

public ILoggingResultSet readLatestMsgRecords(int numberOfRecords)
                                       throws java.lang.IllegalArgumentException,
                                              UnsupportedFormatException,
                                              java.io.FileNotFoundException,
                                              java.lang.SecurityException,
                                              java.io.IOException

Retrieve the latest n messages and return them in a result set in chronological order. This method always refers to the newest messages even the output file is growing and rotating.

Specified by:
readLatestMsgRecords in interface IReadableLog
Parameters:
numMsg - number of messages (>0) to be retrieved
Returns:
retrieved messages packed in LogRecord in chronological order, stored in a list of the result set, with position [0] holding the oldest of the resulting messages.
The resulting list contains all valid available messages, that is, the size may be smaller than the requested number. This can happen if there actually exists fewer messages in the file, including empty file (status valid), or certain messages are getting parsing error (status invalid).
If file is not empty but no valid message can be retrieved, this will return an empty list with status invalid.
Throws:
java.lang.IllegalArgumentException - Negative number or zero messages requested
UnsupportedFormatException - Formatter type not supported by Log Viewer
java.io.FileNotFoundException - Output file not found
java.lang.SecurityException - Access to output file denied
java.io.IOException - Problem reading data from output file

readOldestMsgRecords

public ILoggingResultSet readOldestMsgRecords(int numberOfRecords)
                                       throws java.lang.IllegalArgumentException,
                                              UnsupportedFormatException,
                                              java.io.FileNotFoundException,
                                              java.lang.SecurityException,
                                              java.io.IOException

Retrieve the oldest n messages and return them in a result set in chronological order. This method always refers to the currently available oldest messages which may be different due to the rotating feature from the constantly growing output file size.

Specified by:
readOldestMsgRecords in interface IReadableLog
Parameters:
numMsg - number of messages (>0) to be retrieved
Returns:
retrieved messages packed in LogRecord in chronological order, stored in a list of the result set, with position [0] holding the oldest of the resulting messages.
The resulting list contains all valid available messages, that is, the size may be smaller than the requested number. This can happen if there actually exists fewer messages in the file, including empty file (status valid), or certain messages are getting parsing error (status invalid).
If file is not empty but no valid message can be retrieved, this will return an empty list with status invalid.
Throws:
java.lang.IllegalArgumentException - Negative number or zero messages requested
UnsupportedFormatException - Formatter type not supported by Log Viewer
java.io.FileNotFoundException - Output file not found
java.lang.SecurityException - Access to output file denied
java.io.IOException - Problem reading data from output file

readPrevMsgRecords

public ILoggingResultSet readPrevMsgRecords(int numberOfRecords)
                                     throws java.lang.IllegalArgumentException,
                                            UnsupportedFormatException,
                                            java.io.FileNotFoundException,
                                            java.lang.SecurityException,
                                            java.io.IOException

Continue retrieving x relatively older messages, picked from the point where the last message read from the previous read operation, with respect to the direction of the previous read operation. For example, if previous call is readLatestMsgRecords(5), this call readPrevMsgRecords(2) will retrieve the 7th and 6th lastest messages. If previous call is readOldestMsgRecords(5), this call readPrevMsgRecords(2) will retrieve the 3rd & 4th oldest messages.

If this method is called without a prior call to readLatestMsgRecords(int) or readOldestMsgRecords(int), this will behave the same as calling readLatestMsgRecords(numMsg) .

Messages are returned in a result set in chronological order. Due to the potential file overwriting by the rotating feature, the file being currently referenced to may no longer exist and thus data will become invalid. It is always a good idea to check the overall status of the result set before getting the resulting list.

Specified by:
readPrevMsgRecords in interface IReadableLog
Parameters:
numMsg - number of messages(>0) to be retrieved
Returns:
retrieved messages packed in LogRecord in chronological order, stored in a list of the result set, with position [0] holding the oldest of the resulting messages. Due to the potential rotating feature, you are advised to check the overall status of the result set (isValid()) before retrieving the resulting list.
The resulting list contains all valid available messages, that is, the size may be smaller than the requested number. This can happen if there actually exists fewer messages in the file (status valid), or certain messages are getting parsing error (status invalid).
If no more older message can be retrieved, this will return a valid empty list in the result set. If current file is being overwritten while reading, status set to invalid in result set.
Throws:
java.lang.IllegalArgumentException - Negative number or zero messages requested
UnsupportedFormatException - Formatter type not supported by Log Viewer
java.io.FileNotFoundException - Output file not found
java.lang.SecurityException - Access to output file denied
java.io.IOException - Problem reading data from output file
See Also:
LoggingResultSet, FileLog.LogRecordResultSet

readNextMsgRecords

public ILoggingResultSet readNextMsgRecords(int numberOfRecords)
                                     throws java.lang.IllegalArgumentException,
                                            UnsupportedFormatException,
                                            java.io.FileNotFoundException,
                                            java.lang.SecurityException,
                                            java.io.IOException

Continue retrieving x relatively newer messages, picked from the point where the last message read from the previous read operation, with respect to the direction of the previous read operation. For example, if previous call is readOldestMsgRecords(5), this call readNextMsgRecords(2) will retrieve the 6th and 7th oldest messages. If previous call is readLatestMsgRecords(5), this call readNextMsgRecords(2) will retrieve the 4th & 3rd lastest messages.

If this method is called without a prior call to readLatestMsgRecords(int) or readOldestMsgRecords(int), this will behave the same as calling readOldestMsgRecords(numMsg) .

Messages are returned in a result set in chronological order. Due to the potential file overwriting by the rotating feature, the file being currently referenced to may no longer exist and thus data will become invalid. It is always a good idea to check the overall status of the result set before getting the resulting list.

Specified by:
readNextMsgRecords in interface IReadableLog
Parameters:
numMsg - number of messages(>0) to be retrieved
Returns:
retrieved messages packed in LogRecord in chronological order, stored in a list of the result set, with position [0] holding the oldest of the resulting messages. Due to the potential rotating feature, you are advised to check the overall status of the result set (isValid()) before retrieving the resulting list.
The resulting list contains all valid available messages, that is, the size may be smaller than the requested number. This can happen if there actually exists fewer messages in the file (status valid), or certain messages are getting parsing error (status invalid).
If no more newer message can be retrieved, this will return a valid empty list in the result set. If current file is being overwritten while reading, status set to invalid in result set.
Throws:
java.lang.IllegalArgumentException - Negative number or zero messages requested
UnsupportedFormatException - Formatter type not supported by Log Viewer
java.io.FileNotFoundException - Output file not found
java.lang.SecurityException - Access to output file denied
java.io.IOException - Problem reading data from output file
See Also:
LoggingResultSet, FileLog.LogRecordResultSet

getNextMatch

public ILoggingResultSet getNextMatch(java.lang.String[] searchTokens)
                               throws java.lang.IllegalArgumentException,
                                      UnsupportedFormatException,
                                      java.io.FileNotFoundException,
                                      java.lang.SecurityException,
                                      java.io.IOException
This method returns LoggingResultSet that contains one or zero LogRecords. If the search is successful, there will be one LogRecord. If not, there will be zero records. It takes an array of strings that need to be searched. For now, the first string in the array is the only one to be searched for (August 8, 2003). In future, searching for multiple strings will be supported.
Specified by:
getNextMatch in interface IReadableLog
Parameters:
searchTokens -  
Returns:
A LoggingResultSet of matching LogRecord.
Throws:
java.lang.IllegalArgumentException -  
UnsupportedFormatException -  
java.io.IOException -  

getNextMatch

public ILoggingResultSet getNextMatch(java.lang.String[] searchTokens,
                                      boolean ignoreCase)
                               throws java.lang.IllegalArgumentException,
                                      UnsupportedFormatException,
                                      java.io.FileNotFoundException,
                                      java.lang.SecurityException,
                                      java.io.IOException
This method returns LoggingResultSet that contains one or zero LogRecords. If the search is successful, there will be one LogRecord. If not, there will be zero records. It takes an array of strings that need to be searched. For now, the first string in the array is the only one to be searched for (August 8, 2003). In future, searching for multiple strings will be supported. If ignoreCase is true, it will search for the searchTokens without paying attention to case.
Specified by:
getNextMatch in interface IReadableLog
Parameters:
searchTokens -  
ignoreCase -  
Returns:
A LoggingResultSet of matching LogRecord.
Throws:
java.lang.IllegalArgumentException -  
UnsupportedFormatException -  
java.io.IOException -  

getPreviousMatch

public ILoggingResultSet getPreviousMatch(java.lang.String[] searchTokens)
                                   throws java.lang.IllegalArgumentException,
                                          UnsupportedFormatException,
                                          java.io.FileNotFoundException,
                                          java.lang.SecurityException,
                                          java.io.IOException
This method returns LoggingResultSet that contains one or zero LogRecords. If the search is successful, there will be one LogRecord. If not, there will be zero records. It takes an array of strings that need to be searched. For now, the first string in the array is the only one to be searched for (August 8, 2003). In future, searching for multiple strings will be supported.
Specified by:
getPreviousMatch in interface IReadableLog
Parameters:
searchTokens -  
Returns:
A LoggingResultSet of matching LogRecord.
Throws:
java.lang.IllegalArgumentException -  
UnsupportedFormatException -  
java.io.IOException -  

getPreviousMatch

public ILoggingResultSet getPreviousMatch(java.lang.String[] searchTokens,
                                          boolean ignoreCase)
                                   throws java.lang.IllegalArgumentException,
                                          UnsupportedFormatException,
                                          java.io.FileNotFoundException,
                                          java.lang.SecurityException,
                                          java.io.IOException
This method returns LoggingResultSet that contains one or zero LogRecords. If the search is successful, there will be one LogRecord. If not, there will be zero records. It takes an array of strings that need to be searched. For now, the first string in the array is the only one to be searched for (August 8, 2003). In future, searching for multiple strings will be supported. If ignoreCase is true, it will search for the searchTokens without paying attention to case.
Specified by:
getPreviousMatch in interface IReadableLog
Parameters:
searchTokens -  
ignoreCase -  
Returns:
A LoggingResultSet of matching LogRecord.
Throws:
java.lang.IllegalArgumentException -  
UnsupportedFormatException -  
java.io.IOException -  

areLoggingAttributesEditable

public boolean areLoggingAttributesEditable()
This method verifies whether the attributes like severity can be set.
Specified by:
areLoggingAttributesEditable in interface IReadableLog
Returns:
boolean true if the attributes can be set and false otherwise.

getFileBeingCurrentlyRead

public java.lang.String getFileBeingCurrentlyRead()
This method returns the name of the file that is being currently read. If the file name is empty, it tries to locate the oldest file. It does not check whether or not the file really exists.
Returns:
The name of the file currently being read.

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
This returns the file pointer.
Returns:
-1 if currentFileReader equals null or current file pointer if currentFileReader exists.
Throws:
java.io.IOException -  

seek

public void seek(long filePointer)
          throws java.io.IOException
Tries to set the file pointer specified by the parameter. If currentFileReader is null, it throws RuntimeException.
Parameters:
filePointer -  
Throws:
java.io.IOException -  

getLastModified

public long getLastModified()
                     throws java.io.IOException
Specified by:
getLastModified in interface IReadableLog

status

public int status()
Description copied from interface: ILog
Status of this log object.
Specified by:
status in interface ILog
Overrides:
status in class Log

open

public void open()
Closes output of this log object.
Specified by:
open in interface ILog
Overrides:
open in class Log

close

public void close()
Closes output of this log object.
Specified by:
close in interface ILog
Overrides:
close in class Log

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

readLatestRecords

public java.util.ArrayList readLatestRecords(int numMsg)
                                      throws java.lang.IllegalArgumentException,
                                             UnsupportedFormatException,
                                             java.io.IOException
Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readLatestMsgRecords(int).

Retrieve the latest n messages and return them in an array list. This method always refers to the newest messages even the output file is growing.

Specified by:
readLatestRecords in interface IReadableLog
Parameters:
numMsg - Number of messages (>0) to be retrieved
Returns:
Each retrieved message packed in an array list.
Throws:
UnsupportedFormatException -  
java.lang.IllegalArgumentException - Negative number or zero messages requested
java.io.IOException - Problem reading data from output file

readOldestRecords

public java.util.ArrayList readOldestRecords(int numMsg)
                                      throws java.lang.IllegalArgumentException,
                                             UnsupportedFormatException,
                                             java.io.IOException
Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readOldestMsgRecords(int).

Retrieve the oldest n messages and return them in an array list. This method always refers to the currently available oldest messages which may be different due to the rotating feature(not covered at this stage) from the constantly growing output file size.

Specified by:
readOldestRecords in interface IReadableLog
Parameters:
numMsg - Number of messages (>0) to be retrieved
Returns:
Each retrieved messages packed in an array list.
Throws:
UnsupportedFormatException -  
java.lang.IllegalArgumentException - Negative number or zero messages requested
java.io.IOException - Problem reading data from output file

readPrevRecords

public java.util.ArrayList readPrevRecords(int numMsg)
                                    throws java.lang.IllegalArgumentException,
                                           UnsupportedFormatException,
                                           java.io.IOException
Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readPrevMsgRecords(int).

Continue retrieving x relatively older messages, picked from the point where the last message read from the previous read operation, with respective to the direction of the previous read operation.

If this method is called without a prior call to readLatestRecords(int) or readOldestRecords(int), this will behave the same as calling readLatestRecords(numMsg) .
Messages are returned in an array list.

Specified by:
readPrevRecords in interface IReadableLog
Parameters:
numMsg - Number of messages(>0) to be retrieved
Returns:
Each retrieved messages packed in an array list.
Throws:
UnsupportedFormatException -  
java.lang.IllegalArgumentException - Negative number or zero messages requested
java.io.IOException - Problem reading data from output file

readNextRecords

public java.util.ArrayList readNextRecords(int numMsg)
                                    throws java.lang.IllegalArgumentException,
                                           UnsupportedFormatException,
                                           java.io.IOException
Deprecated. Resulting logrecords do not indicate status which is not good enough for complicated scenario like logfile rotation. It will kept around for a while, but will be eventually replaced by readNextMsgRecords(int).

Continue retrieving x relatively newer messages, picked from the point where the last message read from the previous read operation, with respective to the direction of the previous read operation.

If this method is called without a prior call to readLatestRecords(int) or readOldestRecords(int), this will behave the same as calling readOldestRecords(numMsg) .
Messages are returned in an array list.

Specified by:
readNextRecords in interface IReadableLog
Parameters:
numMsg - Number of messages(>0) to be retrieved
Returns:
Each retrieved messages packed in an array list.
Throws:
UnsupportedFormatException -  
java.lang.IllegalArgumentException - Negative number or zero messages requested
java.io.IOException - Problem reading data from output file

length

public long length()
Deprecated. Use getFileLenght()