Class PatternParser


  • public class PatternParser
    extends Object
    Capable of parsing and expanding a pattern string as used in the TextProtocol and TextFormatter classes. The PatternParser class is capable of creating a text representation of a LogEntry object (see expand). The string representation can be influenced by setting a pattern string. Please see the setPattern method for a description.

    This class is not guaranteed to be threadsafe.

    • Constructor Detail

      • PatternParser

        public PatternParser()
        Creates and initializes a PatternParser instance.
    • Method Detail

      • expand

        public String expand​(LogEntry logEntry)
        Creates a text representation of a LogEntry by applying a user-specified Pattern string.
        Parameters:
        logEntry - The LogEntry whose text representation should be computed by applying the current pattern string. All recognized variables in the pattern string are replaced with the actual values of this LogEntry
        Returns:
        The text representation for the supplied LogEntry object
      • getPattern

        public String getPattern()
        Returns the pattern string for this PatternParser object.

        The pattern string influences the way a text representation of a LogEntry object is created. A pattern string consists of a list of so called variable and literal tokens. When a string representation of a LogEntry object is created, the variables are replaced with the actual values of the LogEntry object. For a list of valid tokens, please refer to the documentation of the setPattern method.

        Returns:
        The pattern string for this PatternParser object
      • setPattern

        public void setPattern​(String pattern)
        Sets the pattern string for this PatternParser object.

        The pattern string influences the way a text representation of a LogEntry object is created. A pattern string consists of a list of so called variable and literal tokens. When a string representation of a LogEntry object is created, the variables are replaced with the actual values of the LogEntry object.

        Variables have a unique name, are surrounded with '%' characters and can have an optional options string enclosed in curly braces like this: %name{options}%.

        You can also specify the minimum width of a value like this: %name,width%. Width must be a valid positive or negative integer. If the width is greater than 0, formatted values will be right-aligned. If the width is less than 0, they will be left-aligned.

        The following table lists the available variables together with the corresponding LogEntry method/property.

        Available variables
        Variable Corresponding Method
        %appname% LogEntry.getAppName
        %color% LogEntry.getColor
        %hostname% LogEntry.getHostName
        %level% LogEntry.getLevel
        %logentrytype% LogEntry.getLogEntryType
        %process% LogEntry.getProcessId
        %session% LogEntry.getSessionName
        %thread% LogEntry.getThreadId
        %timestamp% LogEntry.getTimestamp
        %title% LogEntry.getTitle
        %viewerid% LogEntry.getViewerId

        For the timestamp token, you can use the options string to pass a custom date/time format string. This can look as follows: %timestamp{HH:mm:ss.SSS}%.

        The format string must be a valid Java DateFormat format string. The default format string used by the timestamp token is "yyyy-MM-dd HH:mm:ss.SSS".

        Literals are preserved as specified in the pattern string. When a specified variable is unknown, it is handled as literal.

        Example:

         [%timestamp%] %level,8%: %title%
         [%timestamp%] %session%: %title% (Level: %level%)
         
        Parameters:
        pattern - The new pattern string
      • getIndent

        public boolean getIndent()
        Returns if the expand method automatically intends log packets like in the Views of the SmartInspect Console. Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.
        Returns:
        True if the expand method automatically intends log packets and false otherwise
      • setIndent

        public void setIndent​(boolean indent)
        Sets if the expand method automatically indents log packets like in the Views of the SmartInspect Console.

        Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.

        Parameters:
        indent - Should be true if the expand method should automatically indent log packets and false otherwise