Class SlicingRewritePolicy

  • All Implemented Interfaces:
    org.apache.logging.log4j.core.appender.rewrite.RewritePolicy

    @Plugin(name="SlicingRewritePolicy",
            category="Core",
            elementType="rewritePolicy",
            printObject=true)
    public class SlicingRewritePolicy
    extends Object
    implements org.apache.logging.log4j.core.appender.rewrite.RewritePolicy
    A log rewrite policy to extract bits out of an extremely long log message.

    In IIQ, this might be web services output, a very large configuration object, or other things.

    The goal is to mimic the ‘grep’ command with its -A and -B arguments. When a part of the string matches the regex or the given static substring, a certain number of characters before and after the matching segment will be included in the log message. The remaining message will be dropped.

    Messages that don’t match the regex or substring won’t be included in the log output at all.

    TODO finish this

    • Method Detail

      • createSlicingPolicy

        @PluginFactory
        public static SlicingRewritePolicy createSlicingPolicy​(@PluginAttribute("regex")
                                                               String regex,
                                                               @PluginAttribute("substring")
                                                               String substring,
                                                               @PluginAttribute(value="startChars",defaultInt=50)
                                                               int startChars,
                                                               @PluginAttribute(value="endChars",defaultInt=50)
                                                               int endChars,
                                                               @PluginAttribute(value="contextChars",defaultInt=100)
                                                               int contextChars)
        The log4j2 factory method for creating one of these log event processors
        Parameters:
        regex - The regex to use, if any
        substring - The substring to use, if any
        startChars - The number of characters to log from the start of the string
        endChars - The number of characters to log from the end of the string
        contextChars - The number of characters to print on either side of a regex or substring match
        Returns:
        An instance of this rewrite policy
      • rewrite

        public org.apache.logging.log4j.core.LogEvent rewrite​(org.apache.logging.log4j.core.LogEvent source)
        Specified by:
        rewrite in interface org.apache.logging.log4j.core.appender.rewrite.RewritePolicy
      • extractSlices

        public Queue<com.identityworksllc.iiq.common.logging.SlicingRewritePolicy.StringSlice> extractSlices​(String message)
        API method to extract slices from the given message string, based on the data provided in the class configuration.

        If the message does not match either the substring or regex, the resulting Queue will be empty and the message ought to be ignored for log purposes.

        Parameters:
        message - The message string
        Returns:
        A linked list of string slices