stella.log
Class LogParser

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.log.LogParser
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying
Direct Known Subclasses:
AcquireStarParser, DateParser, FirstOffsetParser, GoodPrimeFocusParser, RandomOffsetParser

public class LogParser
extends PropertyBundles

This class parses the output of a syslogger file to a more useful object type. It produces a list of logline, which consist of a date a log level, possible a host name and a log message.


Nested Class Summary
static class LogParser.Tail
          Test reading from a remote host.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
static DateFormat DEFDATEFORMAT
          Default property value.
private static boolean DEFHASHOST
          Default property value.
static String KEY_DATEFORMAT
          The date format used in the log.
static String KEY_HASHOST
          If true, a host name follows the log level.
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
LogParser(Map<String,String> prop)
          Constructs a new log parser.
 
Method Summary
static List<LogLine> dateFilter(List<LogLine> log, Date start, Date end)
          Filters the log levels from starting to ending date, inclusevely on both edges.
static List<LogLine> dateFilter(List<LogLine> log, Date start, Date end, boolean inv)
          Filters the log levels from starting to ending date, inclusevely on both edges.
static List<LogLine> dateFilter(List<LogLine> log, Date start, long ms)
          Returns a date-filtered list starting from the stated date and spanning for the indicated length in ms.
static List<LogLine> dateFilter(List<LogLine> log, Date start, long ms, boolean inv)
          Returns a date-filtered list starting from the stated date and spanning for the indicated length in ms.
static List<LogLine> dateFilter(List<LogLine> log, long ms, Date end)
          Returns a date-filtered list ending at the stated date and spanning previously for the indicated length in ms.
static List<LogLine> dateFilter(List<LogLine> log, long ms, Date end, boolean inv)
          Returns a date-filtered list ending at the stated date and spanning previously for the indicated length in ms.
static List<LogLine> levelFilter(List<LogLine> log, int level)
          Filters the list of log lines to contain only the requested levels.
 List<LogLine> read(InputStream f)
          Parses a log file to a list of logline objects, from an input stream.
 List<LogLine> read(InputStream f, boolean head)
          Parses a log file to a list of logline objects.
 List<LogLine> readFile(File f)
          Parses a log file to a list of logline objects.
 List<LogLine> readFile(File f, boolean head)
          Parses a log file to a list of logline objects.
 List<LogLine> readList(List<String> lines, boolean head)
          Parses a log file to a list of logline objects.
static List<LogLine> readTail(File f, int n, boolean head, DateFormat df, boolean host)
          Reads log line as tail from a (big) input file.
static List<LogLine> sshTail(String userhost, File f, int n, boolean head, DateFormat df, boolean host)
          Reads a log line from a remote host using ssh tail command.
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, init, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 

Field Detail

KEY_DATEFORMAT

public static final String KEY_DATEFORMAT
The date format used in the log.

See Also:
Constant Field Values

KEY_HASHOST

public static final String KEY_HASHOST
If true, a host name follows the log level.

See Also:
Constant Field Values

DEFDATEFORMAT

public static final DateFormat DEFDATEFORMAT
Default property value.


DEFHASHOST

private static final boolean DEFHASHOST
Default property value.

See Also:
Constant Field Values
Constructor Detail

LogParser

public LogParser(Map<String,String> prop)
Constructs a new log parser.

Method Detail

read

public List<LogLine> read(InputStream f)
                   throws ParseException
Parses a log file to a list of logline objects, from an input stream. Stream is not closed after reading to end.

Throws:
ParseException

read

public List<LogLine> read(InputStream f,
                          boolean head)
                   throws ParseException
Parses a log file to a list of logline objects. If head is true, skip the log-line extension (but record the first part). Stream is not closed after reading to end.

Throws:
ParseException

readFile

public List<LogLine> readFile(File f)
                       throws ParseException
Parses a log file to a list of logline objects.

Throws:
ParseException

readFile

public List<LogLine> readFile(File f,
                              boolean head)
                       throws ParseException
Parses a log file to a list of logline objects. If head is true, skip the log-line extension (but record the first part).

Throws:
ParseException

readList

public List<LogLine> readList(List<String> lines,
                              boolean head)
                       throws ParseException
Parses a log file to a list of logline objects. If head is true, skip the log-line extension (but record the first part).

Throws:
ParseException

levelFilter

public static List<LogLine> levelFilter(List<LogLine> log,
                                        int level)
Filters the list of log lines to contain only the requested levels. Log levels can be combined with 'or' to get certain ranges. A negative filter level means to return all logs that do not contain the requested levels.

The argumental list is not altered by this method.


dateFilter

public static List<LogLine> dateFilter(List<LogLine> log,
                                       long ms,
                                       Date end)
Returns a date-filtered list ending at the stated date and spanning previously for the indicated length in ms.


dateFilter

public static List<LogLine> dateFilter(List<LogLine> log,
                                       long ms,
                                       Date end,
                                       boolean inv)
Returns a date-filtered list ending at the stated date and spanning previously for the indicated length in ms.


dateFilter

public static List<LogLine> dateFilter(List<LogLine> log,
                                       Date start,
                                       long ms)
Returns a date-filtered list starting from the stated date and spanning for the indicated length in ms.


dateFilter

public static List<LogLine> dateFilter(List<LogLine> log,
                                       Date start,
                                       long ms,
                                       boolean inv)
Returns a date-filtered list starting from the stated date and spanning for the indicated length in ms.


dateFilter

public static List<LogLine> dateFilter(List<LogLine> log,
                                       Date start,
                                       Date end)
Filters the log levels from starting to ending date, inclusevely on both edges. If the start or end date is equal null it acts as an open boundary. Returns all log lines within this reange.

Parameters:
start - The minimum date or null for any.
end - The maximum date or null for any.

dateFilter

public static List<LogLine> dateFilter(List<LogLine> log,
                                       Date start,
                                       Date end,
                                       boolean inv)
Filters the log levels from starting to ending date, inclusevely on both edges. If the start or end date is equal null it acts as an open boundary.

Parameters:
start - The minimum date or null for any.
end - The maximum date or null for any.
inv - If true, exclude all logs in the range.

readTail

public static List<LogLine> readTail(File f,
                                     int n,
                                     boolean head,
                                     DateFormat df,
                                     boolean host)
                              throws ParseException,
                                     IOException
Reads log line as tail from a (big) input file.

Throws:
ParseException
IOException

sshTail

public static List<LogLine> sshTail(String userhost,
                                    File f,
                                    int n,
                                    boolean head,
                                    DateFormat df,
                                    boolean host)
                             throws ParseException,
                                    IOException
Reads a log line from a remote host using ssh tail command.

Parameters:
userhost - user and host in form 'user@host'
f - Name of the remote file to tail
n - number of tail lines, 0 for default
head - If true, only main lines are recorded
df - The date format in the file or null if default
host - If false, log file does not contain host information. Defaults to true
Throws:
ParseException
IOException