stella.log
Class LogLine

java.lang.Object
  extended by stella.log.LogLine
All Implemented Interfaces:
Comparable<LogLine>

public class LogLine
extends Object
implements Comparable<LogLine>

Convenience class to hold a log line produced by protomatter. The log line has a format like, where ? means optional

 date [level] ?[channel] ?host ?T:threadname loggerclass?.method()?:line message
    ?some more lines
 
As the host cannot easily be separated from the rest of the log line, we have to indicate wether hosts are used. Updated 29-03-2012 to work with new Syslog class, in particular ProtomatterFormat.


Field Summary
private  String channel
          If we have a channel, this is it.
private  String classname
          The class that called the logger, without package.
private  Date date
          The date parsed from the log line.
private  String host
          The host name, if applicabale.
private  int level
          The log level, one of the five Syslog levels as an int.
private  int linenr
          If we have a line number, zero for none.
static List<String> LOGLEVEL
          No public access to the Syslog log strings, thus repeat here.
static char LOGLEVELEND
          Char that marks the start of the log level indicator.
static char LOGLEVELSTART
          Char that marks the start of the log level indicator.
private  String message
          The log message itself.
private  String method
          If the class is augmented with a method name.
private  String[] multipart
          For multi-part log messages.
private  String thread
          If we have a thread name, this is it.
static String THREADNAME
          The string marking an thread-name start.
 
Constructor Summary
LogLine(String line, DateFormat df, boolean host)
          Constructs a log line without a multipart extension.
LogLine(String line, String[] ext, DateFormat df, boolean hashost)
          Constructs a log line with a multi-part extension given as the following lines after a valid log line.
 
Method Summary
 int compareTo(LogLine o)
          Natural ordering according to date.
private static String extractDate(String line)
          Cuts the first part of the log line, up to '[' and returns the trimmed string.
private static String extractLevel(String line)
          Returns the part of the line between '[' and ']', not including these sparators.
private static String extractRemainder(String line)
          Returns the part of the line between '[' and ']', not including these sparators.
 String getChannel()
          Returns the channel.
 String getClassname()
          Returns the logging class name.
 Date getDate()
          Returns the date.
 String getHost()
          Returns the host name.
 int getLevel()
          Returns the level.
 String getLevelString()
          Returns the level.
 int getLineNumber()
          Returns the line number.
 String getMessage()
          Returns the message part.
 String getMethod()
          Returns the method.
 String[] getMultiline()
          Returns the multi line part of the log message or null, if there isn't any.
 String getThread()
          Returns the thread name.
 long getTimelag(LogLine that)
          Returns the time lag between this log line and the argument, which is negative if the argument is after this.
 int hashCode()
          The hash is the hash of the date.
 boolean isMultiline()
          Tests, if the log-line has a multiline extension.
static boolean isRegular(String line, DateFormat df)
          Returns true, if this line is a regular log line.
 void setMultiline(String[] ext)
          Sets the multiline part of the log line.
 String toLogLine(DateFormat df, boolean showlevel, boolean showchannel, boolean showhost, boolean showthread, boolean showclass, boolean showmethod, boolean showmessage, boolean showextend)
          Converts the log line to s astring using the specified date format.
 String toString()
          Converts to a compact version with a single space separator between items.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOGLEVEL

public static final List<String> LOGLEVEL
No public access to the Syslog log strings, thus repeat here.


LOGLEVELSTART

public static final char LOGLEVELSTART
Char that marks the start of the log level indicator.

See Also:
Constant Field Values

LOGLEVELEND

public static final char LOGLEVELEND
Char that marks the start of the log level indicator.

See Also:
Constant Field Values

THREADNAME

public static final String THREADNAME
The string marking an thread-name start.

See Also:
Constant Field Values

date

private Date date
The date parsed from the log line.


level

private int level
The log level, one of the five Syslog levels as an int.


channel

private String channel
If we have a channel, this is it.


host

private String host
The host name, if applicabale.


thread

private String thread
If we have a thread name, this is it.


classname

private String classname
The class that called the logger, without package.


method

private String method
If the class is augmented with a method name.


linenr

private int linenr
If we have a line number, zero for none.


message

private String message
The log message itself.


multipart

private String[] multipart
For multi-part log messages.

Constructor Detail

LogLine

public LogLine(String line,
               DateFormat df,
               boolean host)
        throws ParseException
Constructs a log line without a multipart extension. This is a logline from a single line. It always starts with the date, followed by the log level in square brackets. If the host is set, the host name follows the log level as a single string token. Anything after that is the message.

Throws:
ParseException

LogLine

public LogLine(String line,
               String[] ext,
               DateFormat df,
               boolean hashost)
        throws ParseException
Constructs a log line with a multi-part extension given as the following lines after a valid log line.

Throws:
ParseException
Method Detail

setMultiline

public void setMultiline(String[] ext)
Sets the multiline part of the log line. Only deferred method, because this might be available only later on log read.


hashCode

public int hashCode()
The hash is the hash of the date.

Overrides:
hashCode in class Object

getDate

public Date getDate()
Returns the date.


getLevel

public int getLevel()
Returns the level.


getLevelString

public String getLevelString()
Returns the level.


getChannel

public String getChannel()
Returns the channel.


getClassname

public String getClassname()
Returns the logging class name.


getMethod

public String getMethod()
Returns the method.


getLineNumber

public int getLineNumber()
Returns the line number.


getThread

public String getThread()
Returns the thread name.


getHost

public String getHost()
Returns the host name.


getMessage

public String getMessage()
Returns the message part.


isMultiline

public boolean isMultiline()
Tests, if the log-line has a multiline extension.


getMultiline

public String[] getMultiline()
Returns the multi line part of the log message or null, if there isn't any.


compareTo

public int compareTo(LogLine o)
Natural ordering according to date.

Specified by:
compareTo in interface Comparable<LogLine>

toString

public String toString()
Converts to a compact version with a single space separator between items. The string returned can again be parsed into a log line, if used with the approbriate date parser, but it is not necessarily identical to the input string.

For converting this log-line using a different date format than the default one, use the toLogLine(java.text.DateFormat, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean) method instead.

Overrides:
toString in class Object

toLogLine

public String toLogLine(DateFormat df,
                        boolean showlevel,
                        boolean showchannel,
                        boolean showhost,
                        boolean showthread,
                        boolean showclass,
                        boolean showmethod,
                        boolean showmessage,
                        boolean showextend)
Converts the log line to s astring using the specified date format. If ths date format is null, the timestamp is printed instead. The separator between the different items is a single space, therefore it is not guaranteed that the string returned here is identically to the input string.


getTimelag

public long getTimelag(LogLine that)
Returns the time lag between this log line and the argument, which is negative if the argument is after this.


isRegular

public static boolean isRegular(String line,
                                DateFormat df)
Returns true, if this line is a regular log line.


extractDate

private static final String extractDate(String line)
Cuts the first part of the log line, up to '[' and returns the trimmed string. If no '[' is found, return null.


extractLevel

private static final String extractLevel(String line)
Returns the part of the line between '[' and ']', not including these sparators.


extractRemainder

private static final String extractRemainder(String line)
Returns the part of the line between '[' and ']', not including these sparators.