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.
|
protected ParsedEntry |
createNewEntry()
Called by the Parser to create and return a new blank log entry to be
used by this Parser.
|
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. |
String |
getDescriptionForUser()
Called by LogMX to get a complete description of this parser to
build error messages.
|
String |
getEntryStringRepresentation(ParsedEntry pEntry)
Called by LogMX to get a textual description of the given Log entry.
|
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).
|
protected LogFileManager |
getLogFileManager()
Called by the Parser to get the
LogFileManager currently used to read the current log. |
protected String |
getParsedFileName()
Called by the Parser to get the name of the file to be parsed by this Parser.
|
abstract String |
getParserName()
Called by LogMX to get the name of this Parser.
|
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. |
abstract String |
getSupportedFileType()
Called by LogMX to get a short description of supported file type(s).
|
String |
getUserDefinedFieldDesription(String pField)
Called by LogMX to get a textual description of the given user-defined field (see
getUserDefinedFields() ). |
List<String> |
getUserDefinedFields()
Called by LogMX to get the ordered list of user-defined fields to display
(given by their key), for each entry.
|
List<Class<?>> |
getUserDefinedFieldsClasses()
Called by LogMX to get the type of each user-defined field (see
getUserDefinedFields() ). |
String |
getVersionInfo()
Called by LogMX to get a Parser version info message to display.
|
void |
init()
Called by the Parser Tests to initialize this Parser.
|
boolean |
isEmitterFieldProvided()
Called by LogMX to detect invalid/incomplete log entries and to decide whether emitters tree
shall be displayed.
|
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. ParsedEntry.getLevel()
null or empty), then LogMX will consider this entry as invalid. |
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).
|
protected void |
removeLastEntry()
Called by the Parser to remove the last entry previously added using
addEntry(ParsedEntry) . |
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 getUserDefinedFieldDesription(String pField)
getUserDefinedFields()
).
null
, which means that the given field
doesn't have any description.pField
- Field for which the textual description should be returnedpField
getUserDefinedFields()
public String getEntryStringRepresentation(ParsedEntry pEntry)
null
, which means that LogMX will use
its default formatter to build a textual description for the given Log entry.null
, LogMX will use the user settings (i.e. which entry fields
to display, in which order) to build a textual description in the "Entry details" GUI panel (below the
log entries table).null
, this String will be used in this GUI panel,
ignoring all user settings concerning this GUI panel. It's possible to tell LogMX to display some text
in bold using the syntax [[B]]...[[/B]]
(HTML formatting NOT supported).pEntry
- Log entry for which the textual description should be returnedpEntry
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)public final void init()
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 © 2025 LightySoft. All rights reserved. [LogMX v8.4.0 (Jan 3, 2025)]