public abstract class LogFileManager extends Object implements Cloneable
releaseResources()
.init(LogURL, String)
getCurrentURL()
setEncoding()
(non-public method used to set the Encoding returned by getEncoding()
)prepareForReading()
supportHeaderReading()
readFileHeader(int)
(if Manager returned true
to supportHeaderReading()
)setEncoding()
and newEncodingDetected()
if a new encoding was detected by LogMX and if Manager supports Encoding auto-detectionreadLine()
until it returns null
getCurrentFileLastModifDate()
periodically (through getCurrentFileInfo()
)getCurrentFileSize()
periodically (through getCurrentFileInfo()
)releaseResources(boolean)
true
in supportHeaderReading()
true
in supportRandomAccess()
readFileHeader(int)
readLineAtOffset(long)
getCurrentOffset()
getCurrentFileSize()
or getCurrentFileLastModifDate()
. The unimplemented method should
always return the same valuetrue
in supportHeaderReading()
readFileHeader(int)
getDecompressedStream(String, InputStream)
with its current input stream as parameter,
to get an uncompressed stream to read fromgetCompressFormat()
to know which compression method is used (e.g. ZIP, GZIP, ...), if any LogStreamManager
LogStreamManager.setHasReadTimeout(boolean)
to enable or disable read timeoutLogFileParser
),
a Manager must (since LogMX v5.2.0):
true
in supportLogEntriesExtraction()
LogEntriesInfoProvider
in getLogEntriesInfoProvider()
to provide LogMX with extracted entries extra information (date format, user-defined fields)readEntry()
to read the next log entry from the underlying resourcecreateNewEntryForExtraction()
to create an instance of a new, initialized log entry instance to enrich in readEntry()
managers/src
" directory of your LogMX distributionManagerSpecVersion
Modifier and Type | Field and Description |
---|---|
Object |
READ_MUTEX
Mutex used by LogMX and the Manager to ensure that only one thread makes this Manager read from the underlying resource, at the same time.
|
Constructor and Description |
---|
LogFileManager()
Default constructor.
Managers should not override it. |
Modifier and Type | Method and Description |
---|---|
boolean |
canUseParser(LogFileParser pParser)
Called by LogMX to know if the given parser can be used to parse the data returned by
this
LogFileManager . |
protected ParsedEntry |
createNewEntryForExtraction()
Called by the Manager to create and return a new blank log entry to be
used by this Manager during entry extraction (see
supportLogEntriesExtraction() ). |
abstract boolean |
deleteFile()
Called by LogMX to delete (i.e. remove from disk) the current file.
|
abstract boolean |
flushFile()
Called by LogMX to flush (i.e. empty) the current file.
|
int |
getAutoRefreshDelay()
Called by LogMX to know the delay (in ms) to wait between each automatic refresh,
for all logs opened with this
LogFileManager . |
String |
getCompressFormat()
Called by the Manager to get the name of the compression method that was
detected during previous call to
getCompressFormatFromFileName(String) and
getDecompressedStream(InputStream, String) . |
String |
getCompressFormatFromFileName(String pFileName)
Called by the Manager to know the compression format that should be used for the given file name
(guessed from its extension: ZIP, GZIP or others).
|
int |
getConnectionTimeout()
Called by the Manager to get the current value (in seconds) for the
user setting "Connection timeout", according to LogMX user preferences set in LogMX GUI.
|
LogFileInfo |
getCurrentFileInfo()
Called periodically by LogMX to get the current file size and date.
|
abstract long |
getCurrentFileLastModifDate()
Called by LogMX to know when the opened resource was modified for the last time.
|
abstract long |
getCurrentFileSize()
Called by LogMX to get the current resource size in bytes.
|
abstract long |
getCurrentOffset()
Called by LogMX to know the current position in file.
|
abstract String |
getCurrentURL()
Called by LogMX to get the current opened URL, matching this Manager URL template.
|
InputStream |
getDecompressedStream(InputStream pInputStream,
String pCompressFormat)
Called by the Manager to get, if needed, a stream of uncompressed data
for the specified logs stream and specified compression format.
|
InputStream |
getDecompressedStream(String pFileName,
InputStream pInputStream)
Called by the Manager to get, if needed, a stream of uncompressed data
for the specified logs stream (case of file compressed with ZIP, GZIP or others).
|
String |
getEncoding()
Called by the Manager to get the Encoding to use when reading bytes.
|
abstract Icon |
getFileTypeIcon()
Called by LogMX to get this Manager icon, which must be a 16x16 icon.
|
Icon |
getFileTypeIcon32x32()
Called by LogMX to get this Manager icon, which must be a 32x32 icon.
|
static Icon |
getIconFile(String pImageFileName)
Called by the Manager to get the image contained in file named
pImageFileName
in LogMX "pics/" directory. |
LogEntriesInfoProvider |
getLogEntriesInfoProvider()
Called by LogMX to request the Manager to provide an object that will enrich
extracted log entries (like Parsers do): log entry date conversions, user-defined fields management.
|
abstract String |
getName()
Called by LogMX to get the name of this Manager.
|
char[] |
getOrAskUserPassword(String pLogin,
String pHost)
Called by the Manager to get a user password saved in LogMX password repository, or by asking
the user their password if the password is not saved in LogMX password repository yet.
|
abstract String |
getProtocolName()
Called by LogMX to get the Protocol handled by this Manager.
|
ProxySettings |
getProxySettings(String pHost)
Called by the Manager to get the proxy settings to use to connect to a host,
according to LogMX user preferences set in LogMX GUI.
|
String |
getShortFilename()
Called by LogMX to get a shorter version of current URL, in order to
display it in GUI file tab.
|
abstract ManagerSpecVersion |
getSpecificationVersion()
Called by LogMX to get the Manager Specification version supported by this Manager.
|
abstract LogURL |
getTemplateLogURL()
Called by LogMX to get a template of
LogURL used by this Manager. |
static String |
getURLFromLogURL(LogURL pLogURL,
String pURLPattern)
Called by the Manager to construct a string URL from a LogURL and a URL pattern.
|
abstract String |
getURLPattern()
Called by LogMX to know how to display a URL handled by this Manager.
|
abstract void |
init(LogURL pLogURL,
String pURLString)
Called by LogMX to initialize the Manager for the specified resource.
|
boolean |
isLiveStream()
Called by LogMX to know if this Manager reads log entries from a
live stream (e.g.
|
void |
newEncodingDetected()
Called by LogMX after
prepareForReading() and
before readLine() if and only if the encoding
to use (to read bytes from the underlying resource) has changed. |
abstract LogFileInfo |
prepareForReading()
Called by LogMX to open the resource previously specified by
init(LogURL, String)
to get ready to read this underlying resource, and return information on this resource (size and date). |
ParsedEntry |
readEntry()
Called by LogMX to request the Manager to extract the next log entry.
|
abstract byte[] |
readFileHeader(int pNumBytes)
Called by LogMX to read the first
pNumBytes bytes from the underlying file or resource. |
abstract String |
readLine()
Called by LogMX to get the next line of text from the underlying Manager resource (file, stream, socket,...).
|
abstract AutoRefreshLineInfo |
readLineAtOffset(long pOffset)
Called by LogMX to read the line of text starting at the specified offset.
|
abstract void |
releaseResources(boolean pSoftRelease)
Called by LogMX when it doesn't need to use this Manager anymore.
|
abstract boolean |
supportFileDelete()
Called by LogMX to know if this Manager can delete (i.e. remove from disk) the current file.
|
abstract boolean |
supportFileFlush()
Called by LogMX to know if this Manager can flush (i.e. empty) the current file.
|
abstract boolean |
supportHeaderReading()
Called by LogMX to know if this Manager support header reading (read a specified number of bytes from the beginning of the file).
|
boolean |
supportLogEntriesExtraction()
Called by LogMX to know if this Manager can extract log entries itself,
without the use of any Log Parser (e.g.
|
abstract boolean |
supportRandomAccess()
Called by LogMX to know if this Manager support random access (read bytes starting at a specified offset).
|
public final Object READ_MUTEX
getCurrentFileLastModifDate()
or getCurrentFileSize()
to be called by LogMX during a specific code execution.public LogFileManager()
releaseResources()
.public abstract String getName()
ManagerSpecVersion
)public abstract LogURL getTemplateLogURL()
LogURL
used by this Manager.
LogURL
can (should) be a static shared instance for better performance.
LogMX will not use it directly but will use a clone of it.LogURL
used by this ManagerManagerSpecVersion
)LogURL
public abstract String getURLPattern()
SimpleText
to denote text "SimpleText"
{MyParam}
to denote the value of LogURLParameter
named "MyParam"
[SimpleOptionalPart]
to denote an optional part containing free text, LogURLParameter
value, or both.scp://{Login}@{Host}:[{Port}:]{File}
scp://john@myhost:22:/mydir/myfile.log
scp://john@myhost:/myfile.log
http://{Host}[:{Port}][/{File}]
http://logmx.com:80/myscript.php?p=4
http://logmx.com:80/mypage.html
http://logmx.com
ManagerSpecVersion
)public abstract void init(LogURL pLogURL, String pURLString) throws Exception
prepareForReading()
).pLogURL
- LogURL for the resource this Manager will have to openpURLString
- String representation for this URL (may be helpful for the Manager, especially to implement
getCurrentURL()
Exception
- If the Manager is not able to process this URLManagerSpecVersion
)public abstract String getProtocolName()
ManagerSpecVersion
)public abstract String readLine() throws Exception
null
if there is no more byte to read.null
if there is no more byte to read.Exception
- If an error occurred while reading bytes. Managers should not handle Exceptions but should
throw them instead, so that LogMX can catch them.ManagerSpecVersion
)public abstract void releaseResources(boolean pSoftRelease)
readLine()
anymore if pSoftRelease
was false
.pSoftRelease
- Used for Auto-Refresh feature: if true
, the Manager must not release resources
needed to read next line of text.ManagerSpecVersion
)public abstract LogFileInfo prepareForReading() throws Exception
init(LogURL, String)
to get ready to read this underlying resource, and return information on this resource (size and date).
Exception
- If the resource could not be opened (this Exception message will be displayed in LogMX GUI)ManagerSpecVersion
)public abstract String getCurrentURL()
init(LogURL, String)
,
or use getURLFromLogURL(LogURL, String)
to construct the URL.ManagerSpecVersion
)getShortFilename()
public String getShortFilename()
abstract
or final
, so that most Managers may
not have to override (i.e. redefine) it, but some others can. The default implementation returns null
which means that LogMX will guess a shorter version of current URL (like "myfile"
for URL
"ftp://john@server/mydir/myfile"
)."ftp://john@server/mydir/myfile?p=1"
,
so that only "myfile"
is displayed in GUI file tab instead of "myfile?p=1"
.null
if not implemented
(shorter version of URL will be guessed)ManagerSpecVersion
)getCurrentURL()
public abstract boolean deleteFile()
supportFileDelete()
returns false
), this method may only contain "return false;
".true
if deletion succeeded, or false
it didn't.ManagerSpecVersion
)public abstract boolean flushFile()
supportFileFlush()
returns false
), this method may only contain "return false;
".true
if flush succeeded, or false
it didn't.ManagerSpecVersion
)public abstract long getCurrentFileLastModifDate() throws Exception
Date.getTime()
.getCurrentFileInfo()
for performances reason) it may return -1, but file-change detection will be affected if getCurrentFileInfo()
also returns -1 as timestamp.Exception
- If the Manager should be able to get the timestamp but could not due to an unexpected event
(e.g. I/O error, authentication failure, timeout, ...)ManagerSpecVersion
)public abstract long getCurrentFileSize() throws Exception
getCurrentFileInfo()
for performances reason), it may return -1, but file-change detection will be affected if getCurrentFileInfo()
also returns -1 as file size.Exception
- If the Manager should be able to get the file size but could not due to an unexpected event
(e.g. I/O error, authentication failure, timeout, ...)ManagerSpecVersion
)public LogFileInfo getCurrentFileInfo() throws Exception
abstract
or final
, so that most Managers may
not have to override (i.e. redefine) it, but some others can. The default implementation returns a LogFileInfo
containing
the file size and date returned by getCurrentFileSize()
and getCurrentFileLastModifDate()
.
Manager must override this new method if getting the file size and file date are both
time-consuming and if they both need a same connection, transaction, context, ...
For example, if getting both file size/date can be performed via a single SFTP "STAT" command,
the Manager shall override getCurrentFileInfo()
so that only one "STAT" command is performed. Note: this method appeared in Manager Specification Version v1.1
is called periodically for file change detection and Auto-Refresh.Exception
- If the Manager should be able to get file info but could not due to an unexpected event
(e.g. I/O error, authentication failure, timeout, ...)ManagerSpecVersion
)public abstract byte[] readFileHeader(int pNumBytes) throws Exception
pNumBytes
bytes from the underlying file or resource.
null
.pNumBytes
- Number of bytes to read. If negative, Manager must read as much bytes as possible
(for example, up to the end of file)null
if Manager doesn't support header readingException
- If Manager could not read bytesManagerSpecVersion
)public abstract AutoRefreshLineInfo readLineAtOffset(long pOffset) throws Exception
null
.pOffset
- Starting offsetnull
if Manager doesn't support header readingException
- If Manager could not read bytesManagerSpecVersion
)public abstract long getCurrentOffset()
ManagerSpecVersion
)public abstract boolean supportFileFlush()
false
is returned, LogMX will not call flushFile()
true
if this Manager can flush the current file, or false
if it can't.ManagerSpecVersion
)public abstract boolean supportFileDelete()
false
is returned, LogMX will not call deleteFile()
true
if this Manager can delete the current file, or false
if it can't.ManagerSpecVersion
)public abstract boolean supportRandomAccess()
false
is returned, LogMX will not call readLineAtOffset(long)
true
if this Manager support random access, or false
if it doesn't.ManagerSpecVersion
)public abstract boolean supportHeaderReading()
false
is returned, LogMX will not call readFileHeader(int)
true
if this Manager support header reading, or false
if it doesn't.ManagerSpecVersion
)public abstract Icon getFileTypeIcon()
getIconFile(String)
to get an icon file
contained in LogMX pictures directory, in order to avoid relative file path issues.null
is returned, a default icon will be used.null
to use a default icon.ManagerSpecVersion
)public Icon getFileTypeIcon32x32()
abstract
so that exiting user-defined Managers
don't have to implement this new method appeared in LogMX v5.2.0. This default implementation calls
getFileTypeIcon()
so that an icon is retrieved, even if it's smaller (16x16) than expected.getIconFile(String)
to get an icon file
contained in LogMX pictures directory, in order to avoid relative file path issues.null
is returned, a default icon will be used.null
to use a default icon.ManagerSpecVersion
)public abstract ManagerSpecVersion getSpecificationVersion()
ManagerSpecVersion.V1_0
ManagerSpecVersion
)public void newEncodingDetected()
prepareForReading()
and
before readLine()
if and only if the encoding
to use (to read bytes from the underlying resource) has changed.
getEncoding()
.
prepareForReading()
. If the encoding found during this auto-detection
is different from the one set while prepareForReading()
was called, this method
newEncodingDetected()
will be called so that the Manager can re-create its Input
Stream Reader before readLine()
is called.getEncoding()
in prepareForReading()
to initialize its Input Stream Reader, or if the Input Stream Reader used in readFileHeader(int)
is also used in readLine()
ManagerSpecVersion
)public boolean isLiveStream()
LogStreamManager
.false
.true
is returned, LogMX will consider that this Manager cannot access random
locations in its underlying stream (e.g. no rewind, no look-ahead, no file header, ...),
so LogMX will not call methods readFileHeader(int)
, readLineAtOffset(long)
, getCurrentOffset()
.true
if this Manager reads log entries from a live stream, false
if it doesn't.ManagerSpecVersion
)public boolean supportLogEntriesExtraction()
false
.true
, LogMX will call readEntry()
and getLogEntriesInfoProvider()
to make the Manager extract entries.true
if this Manager supports log entries extraction, false
if it doesn't.ManagerSpecVersion
)public int getAutoRefreshDelay()
LogFileManager
.
-1
, then LogMX will use the user settings to determine this delay (in Managers
Options, several delays are tunable depending on Manager type: local file, socket, others).-1
.-1
to use value given by user settingspublic ParsedEntry readEntry() throws Exception
null
.true
in supportLogEntriesExtraction()
.
Note: the Manager shall use createNewEntryForExtraction()
to get an instance of ParsedEntry
to enrich.null
if no entry can be extracted at this timeException
- If the Manager couldn't extract the next log entryManagerSpecVersion
)public LogEntriesInfoProvider getLogEntriesInfoProvider()
null
.true
in supportLogEntriesExtraction()
.
Note: the Manager shall use createNewEntryForExtraction()
to get an instance of ParsedEntry
to enrich.LogEntriesInfoProvider
to be used by LogMX to convert log entry timestamp, and handle user-defined
fieldsManagerSpecVersion
)public boolean canUseParser(LogFileParser pParser)
LogFileManager
.
false
, then LogMX will not attempt to parse the logs with the given parser
when reading content with this LogFileManager
.true
.pParser
- Parser that LogMX would like to use to parse logs out of this LogFileManager
's returned contenttrue
if LogMX can attempt to parse logs with the given parser, or
false
if LogMX should NOT attempt to parse logs with the given parserpublic final String getEncoding()
new InputStreamReader(myStream, getEncoding());
ManagerSpecVersion
)public static final Icon getIconFile(String pImageFileName)
pImageFileName
in LogMX "pics/" directory.
pImageFileName
- File name, without path (e.g. "my_pic.png")pImageFileName
ManagerSpecVersion
)public static final String getURLFromLogURL(LogURL pLogURL, String pURLPattern)
pLogURL
- LogURL containing parameters and their valuepURLPattern
- URL Pattern as described for getURLPattern()
ManagerSpecVersion
)public final char[] getOrAskUserPassword(String pLogin, String pHost)
char[]
for security reasons, so that you can flush it efficiently from memory.pLogin
- User loginpHost
- Host to access (used to save a password per host, and per protocol using getProtocolName()
)char
array for security reasons, so that you can flush it efficiently from memory).
Method returns null
if password couldn't be retrieved from LogMX password repository, or if
user dismissed password request dialog.ManagerSpecVersion
)public final ProxySettings getProxySettings(String pHost)
getProtocolName()
on this Manager.pHost
- Host to accessManagerSpecVersion
)public final int getConnectionTimeout()
ManagerSpecVersion
)public final InputStream getDecompressedStream(String pFileName, InputStream pInputStream)
getCompressFormatFromFileName(String)
and then
getDecompressedStream(InputStream, String)
, instead of this method, because it may be wrong to detect if a
decompressed stream is required, after opening an InputStream
: if the Manager tries to open this InputStream
at an offset different than 0 (e.g. for AutoRefresh or Tail), it will be impossible to construct a
decompressed stream from this InputStream (compression algorithms usually need to read the file header
before seeking an offset).InputStream
is returned.getCompressFormat()
).pInputStream
:
for example, closing the returned stream will also close the specified underlying stream even if it contains
compressed data.pFileName
- Log file name (used to recognize compression method in its extension, like .gz, .zip, ...)pInputStream
- Stream used to read logs from. Decompression process will read from this stream.pInputStream
will be returned, as is.ManagerSpecVersion
)public final String getCompressFormatFromFileName(String pFileName)
null
is returned.getCompressFormat()
).null
.pFileName
- Log file name (used to recognize compression method in its extension, like .gz, .zip, ...)getCompressFormat()
, otherwise,
returns null
public final InputStream getDecompressedStream(InputStream pInputStream, String pCompressFormat)
(pInputStream == null)
, then the specified InputStream
is returned.InputStream
is returned.pInputStream
:
for example, closing the returned stream will also close the specified underlying stream even if it contains
compressed data.pInputStream
- Stream used to read logs from. Decompression process will read from this stream.pCompressFormat
- Compression format to use (one of the String constants described in Javadoc of getCompressFormat()
,
usually obtained from getCompressFormatFromFileName(String)
)InputStream
if the
given pCompressFormat
cannot be used (error while creating decompressed stream, or decompression
deactivated in user preferences).public final String getCompressFormat()
getCompressFormatFromFileName(String)
and
getDecompressedStream(InputStream, String)
.
null
."ZIP"
"GZIP"
"TAR-GZIP"
"BZ2"
"TAR-BZ2"
"LZMA"
"TAR-LZMA"
"XZ"
"TAR-XZ"
"ZLIB"
getCompressFormatFromFileName(String)
and getDecompressedStream(InputStream, String)
,
or null
if the input stream was not considered as compressed (or if getCompressFormatFromFileName(String)
was not called yet)ManagerSpecVersion
)protected final ParsedEntry createNewEntryForExtraction()
supportLogEntriesExtraction()
).
ManagerSpecVersion
)Copyright © 2025 LightySoft. All rights reserved. [LogMX v8.4.0 (Jan 3, 2025)]