Class TextProtocol
- java.lang.Object
-
- com.gurock.smartinspect.protocols.Protocol
-
- com.gurock.smartinspect.protocols.FileProtocol
-
- com.gurock.smartinspect.protocols.TextProtocol
-
public class TextProtocol extends FileProtocol
Used for writing customizable plain text log files.TextProtocol is used for writing plain text log files. This class is used when the 'text' protocol is specified in the connections string. See the
SmartInspect.setConnections(java.lang.String)method for a list of available protocol options.The public members of this class are threadsafe.
-
-
Field Summary
-
Fields inherited from class com.gurock.smartinspect.protocols.Protocol
fConnected
-
-
Constructor Summary
Constructors Constructor Description TextProtocol()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildOptions(ConnectionsBuilder builder)Overridden.protected StringgetDefaultFileName()Returns the default filename for this log file protocol.protected FormattergetFormatter()Returns the formatter for this log file protocol.protected StringgetName()Overridden.protected booleanisValidOption(String name)Overridden.protected voidloadOptions()Overridden.protected voidwriteFooter(OutputStream stream)Overridden.protected longwriteHeader(OutputStream stream, long size)Overridden.-
Methods inherited from class com.gurock.smartinspect.protocols.FileProtocol
getStream, internalConnect, internalDisconnect, internalWritePacket
-
Methods inherited from class com.gurock.smartinspect.protocols.Protocol
addListener, composeLogHeaderPacket, connect, disconnect, dispatch, dispose, doError, failed, getAppName, getAsyncEnabledDefaultValue, getAsyncQueueDefaultValue, getAsyncThrottleDefaultValue, 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, writePacket
-
-
-
-
Method Detail
-
getName
protected String getName()
Overridden. Returns "text".- Overrides:
getNamein classFileProtocol- Returns:
- Just "text". Derived classes can change this behavior by overriding this method
-
getFormatter
protected Formatter getFormatter()
Returns the formatter for this log file protocol.The standard implementation of this method returns an instance of the TextFormatter class. Derived classes can change this behavior by overriding this method.
- Overrides:
getFormatterin classFileProtocol- Returns:
- The formatter for this log file protocol
-
getDefaultFileName
protected String getDefaultFileName()
Returns the default filename for this log file protocol. The standard implementation of this method returns the string "log.txt" here. Derived classes can change this behavior by overriding this method.- Overrides:
getDefaultFileNamein classFileProtocol- Returns:
- The default filename for this log file protocol
-
writeHeader
protected long writeHeader(OutputStream stream, long size) throws IOException
Overridden. Intended to write the header of a log file. The implementation of this method writes the standard UTF8 BOM (byte order mark) to the supplied stream in order to identify the log file as text file in UTF8 encoding. Derived classes may change this behavior by overriding this method.- Overrides:
writeHeaderin classFileProtocol- Parameters:
stream- The stream to which the header should be written tosize- Specifies the current size of the supplied stream- Returns:
- The new size of the stream after writing the header. If no header is written, the supplied size argument is returned
- Throws:
IOException- io exception
-
writeFooter
protected void writeFooter(OutputStream stream)
Overridden. Intended to write the footer of a log file.The implementation of this method does nothing. Derived class may change this behavior by overriding this method.
- Overrides:
writeFooterin classFileProtocol- Parameters:
stream- The stream to which the footer should be written to
-
buildOptions
protected void buildOptions(ConnectionsBuilder builder)
Overridden. Fills a ConnectionsBuilder instance with the options currently used by this text protocol.- Overrides:
buildOptionsin classFileProtocol- Parameters:
builder- The ConnectionsBuilder object to fill with the current options of this protocol
-
isValidOption
protected boolean isValidOption(String name)
Overridden. Validates if a protocol option is supported.Text protocol options Valid Options Default Value Description indent false Indicates if the logging output should automatically be indented like in the Console pattern "[%timestamp%] %level%: %title%" Specifies the pattern used to create a text representation of a packet For detailed information of how a pattern string can look like, please have a look at the documentation of the PatternParser class, especially the PatternParser.setPattern method.
The following table lists all valid options, their default values and descriptions for this text file protocol. For a list of options common to all file protocols, please have a look at the isValidOption method of the parent class. Please note that this text protocol does not support log file encryption.
SiAuto.Si.setConnections("text()"); SiAuto.Si.setConnections("text(filename=\"log.txt\", append=true)"); SiAuto.Si.setConnections("text(filename=\"log.txt\")"); SiAuto.Si.setConnections("text(maxsize=\"16MB\")"); }- Overrides:
isValidOptionin classFileProtocol- Parameters:
name- The option name to validate.- Returns:
- True if the option is supported and false otherwise.
-
loadOptions
protected void loadOptions()
Overridden. Loads and inspects file specific options. This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the file protocol.- Overrides:
loadOptionsin classFileProtocol
-
-