public class FileProtocol extends Protocol
Thread safety: The public members of this class are threadsafe.
fConnected| Constructor and Description |
|---|
FileProtocol()
Creates and initializes a new FileProtocol instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
buildOptions(ConnectionsBuilder builder)
Overridden.
|
protected String |
getDefaultFileName()
Returns the default filename for this log file protocol.
|
protected Formatter |
getFormatter()
Returns the formatter for this log file protocol.
|
protected String |
getName()
Overridden.
|
protected OutputStream |
getStream(OutputStream stream)
Intended to provide a wrapper stream for the underlying file stream.
|
protected void |
internalConnect()
Overridden.
|
protected void |
internalDisconnect()
Overridden.
|
protected void |
internalWritePacket(Packet packet)
Overridden.
|
protected boolean |
isValidOption(String name)
Overridden.
|
protected void |
loadOptions()
Overridden.
|
protected void |
writeFooter(OutputStream stream)
Overridden.
|
protected long |
writeHeader(OutputStream stream,
long size)
Overridden.
|
addListener, composeLogHeaderPacket, connect, disconnect, dispatch, dispose, doError, failed, getAppName, getAsyncEnabledDefaultValue, getAsyncQueueDefaultValue, getBooleanOption, getBytesOption, getCaption, getHostName, getIntegerOption, getLevelOption, getReconnectDefaultValue, getRotateOption, getSizeOption, getStringOption, getTimespanOption, handleException, implConnect, implDisconnect, implDispatch, implWritePacket, initialize, internalDispatch, internalReconnect, internalWriteLogHeader, isAsynchronous, removeListener, reset, scheduleWritePacket, setAppName, setHostName, writePacketpublic FileProtocol()
protected String getName()
protected Formatter getFormatter()
protected String getDefaultFileName()
The standard implementation of this method returns the string "log.sil" here. Derived classes can change this behavior by overriding this method.
protected OutputStream getStream(OutputStream stream)
stream - The underlying file stream.protected boolean isValidOption(String name)
The following table lists all valid options, their default values and descriptions for the file protocol.
| Valid Options | Default Value | Description |
|---|---|---|
| append | false | Specifies if new packets should be appended to the destination file instead of overwriting the file first. |
| buffer | 0 | Specifies the I/O buffer size in kilobytes. It is possible to specify size units like this: "1 MB". Supported units are "KB", "MB" and "GB". A value of 0 disables this feature. Enabling the I/O buffering greatly improves the logging performance but has the disadvantage that log packets are temporarily stored in memory and are not immediately written to disk. |
| encrypt | false | Specifies if the resulting log file should be encrypted. Note that the 'append' option cannot be used with encryption enabled. If encryption is enabled the 'append' option has no effect. |
| filename | [varies] | Specifies the filename of the log. |
| key | [empty] | Specifies the secret encryption key as string if the 'encrypt' option is enabled. |
| maxparts | [varies] | Specifies the maximum amount of log files at any given time when log rotating is enabled or the maxsize option is set. Specify 0 for no limit. See below for information on the default value for this option. |
| maxsize | 0 | Specifies the maximum size of a log file in kilobytes. When this size is reached, the current log file is closed and a new file is opened. The maximum amount of log files can be set with the maxparts option. It is possible to specify size units like this: "1 MB". Supported units are "KB", "MB" and "GB". A value of 0 disables this feature. |
| rotate | none | Specifies the rotate mode for log files. Please see below for a list of available values. A value of "none" disables this feature. The maximum amount of log files can be set with the maxparts option. |
When using the standard binary log file protocol ("file" in
the SmartInspect.setConnections),
the default filename is set to "log.sil". When using text log
files ("text" in the SmartInspect.setConnections),
the default filename is "log.txt".
Example usage:
SiAuto.si.setConnections("file()");
SiAuto.si.setConnections("file(filename=\"log.sil\", append=true)");
SiAuto.si.setConnections("file(filename=\"log.sil\")");
SiAuto.si.setConnections("file(maxsize=\"16MB\", maxparts=5)");
SiAuto.si.setConnections("file(rotate=weekly)");
SiAuto.si.setConnections("file(encrypt=true, key=\"secret\")");
isValidOption in class Protocolname - The option name to validate.protected void buildOptions(ConnectionsBuilder builder)
buildOptions in class Protocolbuilder - The ConnectionsBuilder object to fill with the current options
of this protocol.protected void loadOptions()
This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the file protocol.
loadOptions in class Protocolprotected void internalConnect()
throws Exception
This method tries to open the destination file, which can be specified by passing the "filename" option to the initialize method. For other valid options which might affect the behavior of this method, please see the isValidOption method.
internalConnect in class ProtocolException - if opening the destination file failed.protected long writeHeader(OutputStream stream, long size) throws IOException
stream - The stream to which the header should be written to.size - Specifies the current size of the supplied stream.IOException - io exceptionprotected void writeFooter(OutputStream stream)
The implementation of this method does nothing. Derived class may change this behavior by overriding this method.
stream - The stream to which the footer should be written to.protected void internalWritePacket(Packet packet) throws Exception
If the "maxsize" option is set and the supplied packet would exceed the maximum size of the destination file, then the current log file is closed and a new file is opened. Additionally, if the "rotate" option is active, the log file is rotated if necessary. Please see the documentation of the isValidOption method for more information.
internalWritePacket in class Protocolpacket - The packet to write.Exception - If writing the packet to the destination file fails.protected void internalDisconnect()
throws Exception
This method closes the underlying file handle if previously created and disposes any supplemental objects.
internalDisconnect in class ProtocolException - if closing the destination file fails.Copyright © 2023. All rights reserved.