org.apache.cxf.management.web.logging
Class ReadOnlyFileStorage

java.lang.Object
  extended by org.apache.cxf.management.web.logging.ReadOnlyFileStorage
All Implemented Interfaces:
ReadableLogStorage

public class ReadOnlyFileStorage
extends Object
implements ReadableLogStorage

Facilitates reading the log entries from the existing log files.


Nested Class Summary
protected static class ReadOnlyFileStorage.FileInfo
           
protected  class ReadOnlyFileStorage.FileInfoComparator
           
protected static class ReadOnlyFileStorage.PageInfo
           
 
Field Summary
static String CATEGORY_PROPERTY
           
static String DATE_ONLY_FORMAT
           
static String DATE_PROPERTY
           
static String LEVEL_PROPERTY
           
static String MESSAGE_PROPERTY
           
static String THREAD_PROPERTY
           
 
Constructor Summary
ReadOnlyFileStorage()
           
 
Method Summary
 void close()
          Close the storage
protected  LogRecord createRecord(Map<Integer,String> map, ReadOnlyFileStorage.FileInfo logFileInfo)
           
 int getSize()
          Get the size of storage (in records)
 int load(List<LogRecord> list, org.apache.cxf.jaxrs.ext.search.SearchCondition<LogRecord> condition, int pageNumber, int pageSize)
          Read the records and load them into a provided list
protected  LogRecord readRecord(ReadOnlyFileStorage.FileInfo logFileInfo)
           
protected  void readTheLine(RandomAccessFile logFile, Map<Integer,String> map, int columnIndex)
           
 void setColumnSep(String columnSep)
          Log column separator such as '|'
 void setColumnsMap(Map<Integer,String> columnsMap)
          Identifies the columns which this reader should use when creating a LogRecord.
 void setFileNameComparator(Comparator<String> comp)
          Optional comparator which can be used for sorting the new log files found after the latest scan iteration.
 void setFileNameDateFormat(String fileNameDateFormat)
          Optional pattern for parsing the file date
 void setFileNameDatePattern(String fileNameDatePattern)
          Sets the regular expression for capturing the date from the file name If set then it must contain a single capturing group only.
 void setLevelsMap(Map<String,String> map)
          Optional map for converting the levels.
 void setLogLocation(String location)
          Sets the log location.
 void setLogLocations(List<String> locations)
          A list of log files, the oldest files are expected to be in the top of the list
protected  void setLogRecordDate(LogRecord record, String logDate, ReadOnlyFileStorage.FileInfo logFileInfo)
           
protected  void setLogRecordLevel(LogRecord record, String logLevel)
           
 void setNumberOfColumns(String number)
          Sets the number of columns per record
 void setRecordDateFormat(String format)
          The format for parsing the log date
 void setUseFileModifiedDate(boolean useFileModifiedDate)
          Indicates if the file modified date needs to be used for creating a LogRecord date - in case the actual log record contains no year/month/hour information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEVEL_PROPERTY

public static final String LEVEL_PROPERTY
See Also:
Constant Field Values

DATE_PROPERTY

public static final String DATE_PROPERTY
See Also:
Constant Field Values

MESSAGE_PROPERTY

public static final String MESSAGE_PROPERTY
See Also:
Constant Field Values

CATEGORY_PROPERTY

public static final String CATEGORY_PROPERTY
See Also:
Constant Field Values

THREAD_PROPERTY

public static final String THREAD_PROPERTY
See Also:
Constant Field Values

DATE_ONLY_FORMAT

public static final String DATE_ONLY_FORMAT
See Also:
Constant Field Values
Constructor Detail

ReadOnlyFileStorage

public ReadOnlyFileStorage()
Method Detail

getSize

public int getSize()
Get the size of storage (in records)

Specified by:
getSize in interface ReadableLogStorage
Returns:
the size, -1 if not known, for ex, when reading from an open file containing log entries

load

public int load(List<LogRecord> list,
                org.apache.cxf.jaxrs.ext.search.SearchCondition<LogRecord> condition,
                int pageNumber,
                int pageSize)
Read the records and load them into a provided list

Specified by:
load in interface ReadableLogStorage
Parameters:
list - the list saved records should be added to
condition - the condition loaded records must meet, can be null
pageNumber - the initial page to have records loaded from
Returns:
the current page number; it may be different from the starting page if certain records within the given page range did not match the search condition.

readRecord

protected LogRecord readRecord(ReadOnlyFileStorage.FileInfo logFileInfo)

createRecord

protected LogRecord createRecord(Map<Integer,String> map,
                                 ReadOnlyFileStorage.FileInfo logFileInfo)

setLogRecordLevel

protected void setLogRecordLevel(LogRecord record,
                                 String logLevel)

setLogRecordDate

protected void setLogRecordDate(LogRecord record,
                                String logDate,
                                ReadOnlyFileStorage.FileInfo logFileInfo)

readTheLine

protected void readTheLine(RandomAccessFile logFile,
                           Map<Integer,String> map,
                           int columnIndex)
                    throws IOException
Throws:
IOException

setColumnSep

public void setColumnSep(String columnSep)
Log column separator such as '|'

Parameters:
columnSep - the separator

setNumberOfColumns

public void setNumberOfColumns(String number)
Sets the number of columns per record

Parameters:
number - the number of columns per record

setColumnsMap

public void setColumnsMap(Map<Integer,String> columnsMap)
Identifies the columns which this reader should use when creating a LogRecord. Example, given a 7-columns record a user may only need the information from 1, 2, and the last column. Regular expressions are not suitable.

Parameters:
columnsMap - the map, the key is the column number (starting from 1) and the value is the name of the property such as 'message'. The following properties are supported at the moment: 'date', 'level' 'category', 'thread', 'message'.

setLogLocations

public void setLogLocations(List<String> locations)
A list of log files, the oldest files are expected to be in the top of the list

Parameters:
locations - the locations

setLogLocation

public void setLogLocation(String location)
Sets the log location.

Parameters:
location - the location, if it is a directory then the on-demand scanning will be enabled

setRecordDateFormat

public void setRecordDateFormat(String format)
The format for parsing the log date

Please see SimpleDateFormat


setLevelsMap

public void setLevelsMap(Map<String,String> map)
Optional map for converting the levels. This map is not required if the log records have levels with one of the following values: 'WARN', 'ERROR', 'DEBUG', 'TRACE', 'INFO', 'FATAL'.

Parameters:
map - the map of levels

setFileNameComparator

public void setFileNameComparator(Comparator<String> comp)
Optional comparator which can be used for sorting the new log files found after the latest scan iteration. If scanning is enabled then by default the file names are compared using either the embedded date (provided the fileNameDatePattern is set) or the last segment in the file name which is expected to be a number. The files with the oldest dates or bigger indexes will be positioned first.

Parameters:
comp - the comparator

close

public void close()
Description copied from interface: ReadableLogStorage
Close the storage

Specified by:
close in interface ReadableLogStorage

setUseFileModifiedDate

public void setUseFileModifiedDate(boolean useFileModifiedDate)
Indicates if the file modified date needs to be used for creating a LogRecord date - in case the actual log record contains no year/month/hour information.


setFileNameDatePattern

public void setFileNameDatePattern(String fileNameDatePattern)
Sets the regular expression for capturing the date from the file name If set then it must contain a single capturing group only.

Parameters:
fileNameDatePattern -

setFileNameDateFormat

public void setFileNameDateFormat(String fileNameDateFormat)
Optional pattern for parsing the file date

Parameters:
fileNameDateFormat -


Apache CXF