Class 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.

    • Constructor Detail

      • TextProtocol

        public TextProtocol()
    • Method Detail

      • getName

        protected String getName()
        Overridden. Returns "text".
        Overrides:
        getName in class FileProtocol
        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:
        getFormatter in class FileProtocol
        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:
        getDefaultFileName in class FileProtocol
        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:
        writeHeader in class FileProtocol
        Parameters:
        stream - The stream to which the header should be written to
        size - 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:
        writeFooter in class FileProtocol
        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:
        buildOptions in class FileProtocol
        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 OptionsDefault ValueDescription
        indentfalseIndicates 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:
        isValidOption in class FileProtocol
        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:
        loadOptions in class FileProtocol