public abstract class LogFileParser extends Object implements Cloneable
parseLine(String)
), and shall parse these lines
into log entries (addEntry(ParsedEntry)
).ParsedEntry
Constructor and Description |
---|
LogFileParser()
Default constructor.
Parsers don't have to override this constructor. |
Modifier and Type | Method and Description |
---|---|
protected void |
addEntry(ParsedEntry pParsedEntry)
Called by the Parser for each entry it has successfully parsed.
Calling this method several consecutive times with the same pParsedEntry
produces no effect in most cases. |
protected ParsedEntry |
createNewEntry()
Called by the Parser to create and return a new blank log entry to be
used by this Parser.
Parsers should not try to directly create entries instead of calling this method. |
abstract Date |
getAbsoluteEntryDate(ParsedEntry pEntry)
Called by LogMX to get the
Date of the specified entry,
or null if this Parser could not return the Date for this entry.Parser should try to get this Date from the String given by pEntry.getDate() . |
String |
getDescriptionForUser()
Called by LogMX to get a complete description of this parser to
build error messages.
Implementing this method is optional for Parsers. |
String |
getGUIName()
Called by the Parser to get the name of this parser, as set in LogMX GUI options
(may be used to build error messages for example).
|
int |
getLastParsedLineNumber()
Called by the Parser to get the last parsed line number.
|
protected Locale |
getLocale()
Called by the Parser to get the Locale to use by this Parser
(useful for Date & Time format handling).
Parsers should not call this method in constructor (will return null ). |
protected LogFileManager |
getLogFileManager()
Called by the Parser to get the
LogFileManager currently used to read the current log.LogMX may return null in some cases (internal parsing, Parser test wizard, ...). |
protected String |
getParsedFileName()
Called by the Parser to get the name of the file to be parsed by this Parser.
Parsers should not call this method in constructor (will return null ). |
abstract String |
getParserName()
Called by LogMX to get the name of this Parser.
All Parsers must implement this method to return a short name (~3 words maximum) that will be displayed in LogMX GUI. |
abstract Date |
getRelativeEntryDate(ParsedEntry pEntry)
Called by LogMX to get a timestamp for entry
pEntry ,
or null if this Parser doesn't support relative timestamps.A relative timestamp is a timestamp relative to any arbitrary start date (in many cases, T0 matches the launch of the process that writes the log file).Parser should try to get this timestamp from the data given by pEntry.getExtraInfo()
or pEntry.getDate() . |
abstract String |
getSupportedFileType()
Called by LogMX to get a short description of supported file type(s).
All Parsers must implement this method to return a short description (~3 words maximum) of supported file type(s) (will be displayed in LogMX GUI). |
List<String> |
getUserDefinedFields()
Called by LogMX to get the ordered list of user-defined fields to display
(given by their key), for each entry.
The default implementation for this class is to return an empty list (i.e. |
List<Class<?>> |
getUserDefinedFieldsClasses()
Called by LogMX to get the type of each user-defined field (see
getUserDefinedFields() ).The default implementation for this class is to return an empty list, which means that LogMX will assume that all user-defined fields are String . |
String |
getVersionInfo()
Called by LogMX to get a Parser version info message to display.
Implementing this method is optional for Parsers. |
boolean |
isEmitterFieldProvided()
Called by LogMX to detect invalid/incomplete log entries and to decide whether emitters tree
shall be displayed.
If this method returns true :
If this Parser produces an entry without any Emitter (i.e. |
boolean |
isLevelFieldProvided()
Called by LogMX to detect invalid/incomplete log entries: if this method returns
true
but this Parser produces an entry without any Level (i.e. |
protected abstract void |
parseLine(String pLine)
Called by LogMX each time a new line is read from the underlying
media by the LogFileManager (eg: a line is read from a local file).
LogFileManager contract implies this line contains no line terminator (\n or \r). All Parsers must implement this method and process all lines given by this method. |
protected void |
removeLastEntry()
Called by the Parser to remove the last entry previously added using
addEntry(ParsedEntry) .Calling this method when no entry was added has no effect. |
public LogFileParser()
protected abstract void parseLine(String pLine) throws Exception
pLine
- New line to process by Parser (should not contain \n or \r).null
, that means the LogFileManager has no more line to read.Exception
- If an unexpected error occurs while Parser processed new line. LogMX will then notify
the user with a dialog box and will try to parse the file with the next parserpublic abstract Date getRelativeEntryDate(ParsedEntry pEntry) throws Exception
pEntry
,
or null
if this Parser doesn't support relative timestamps.T0
matches the launch of the process that writes the log file).pEntry.getExtraInfo()
or pEntry.getDate()
.
This timestamp can be a complete Date (from milliseconds to year), or a simple number of milliseconds
relative to this entry (e.g.: new Date(125)
).e1
and e2
are 'separated' by X milliseconds, thengetRelativeEntryDate(e1).getTime() - getRelativeEntryDate(e2).getTime() |
pEntry
.pEntry
- Entry which timestamp must be computedpEntry
, or null
if this Parser
doesn't support relative timestampsException
- If an unexpected error occurs while computing timestamp (should not happen: if Parser can't
compute timestamp for this entry, it should return null
)public abstract Date getAbsoluteEntryDate(ParsedEntry pEntry) throws Exception
Date
of the specified entry,
or null
if this Parser could not return the Date for this entry.Date
from the String
given by pEntry.getDate()
.
This Date
must be a complete one, from Year to Milliseconds (or seconds if file format is not accurate enough).
pEntry
.pEntry
- Entry which Date
must be computedpEntry
, or null
if this Parser could not return its DateException
- If an unexpected error occurs while computing Datepublic abstract String getParserName()
public abstract String getSupportedFileType()
public String getDescriptionForUser()
String
returned by
getParserName()
, depending on the available
information.public List<String> getUserDefinedFields()
ParsedEntry.getUserDefinedFields()
.getUserDefinedFieldsClasses()
public List<Class<?>> getUserDefinedFieldsClasses()
getUserDefinedFields()
).String
.
The order of these types must match the order given by getUserDefinedFields()
.
Parser should override this method if it wants to use entries user-defined fields that should not be treated as String
values (for example, if a user-defined field is declared as an Integer
, sorting log entries
by this field will produce the order {1, 2, 10} instead of {1, 10, 2}).getUserDefinedFields()
public String getVersionInfo()
null
.public boolean isEmitterFieldProvided()
true
:
ParsedEntry.getEmitter()
null
or empty), then LogMX will consider this entry as invalid, and may then decide to ignore it.false
:
true
.true
if this Parser usually sets entries 'Emitter' field (false
if it never uses emitters)public boolean isLevelFieldProvided()
true
but this Parser produces an entry without any Level (i.e. ParsedEntry.getLevel()
null
or empty), then LogMX will consider this entry as invalid.true
.true
if this Parser usually sets entries 'Level' field (false
otherwise)protected final ParsedEntry createNewEntry()
protected final void addEntry(ParsedEntry pParsedEntry) throws Exception
pParsedEntry
produces no effect in most cases. However, when used for AutoRefresh, this method can be called for the same
pParsedEntry
each time this entry has been enriched by this Parser (e.g: new line of text
available for 'Message' entry field). In this case, LogMX will update this entry on each call.pParsedEntry
- Entry parsed by ParserException
- If pParsedEntry.getLevel()
is an invalid Level and user wants to abort
this Parser process (LogMX will then switch to next Parser). Parser should NOT
catch this Exception: its method parseLine(String)
should simply 'propagate' this Exception so that LogMX can process it.protected final void removeLastEntry()
addEntry(ParsedEntry)
.protected final Locale getLocale()
null
).protected final String getParsedFileName()
null
).protected final LogFileManager getLogFileManager()
LogFileManager
currently used to read the current log.null
in some cases (internal parsing, Parser test wizard, ...). This method may be useful to get
more technical information on the underlying data source in order to enrich parsed log entries (e.g. remote IP/port sending the logs,
database version, ...)null
if no Manager at this timepublic final int getLastParsedLineNumber()
public final String getGUIName()
Copyright © 2017 LightySoft. All rights reserved. [LogMX v6.0.2 (November 20, 2017)]