Class SlicingRewritePolicy
- java.lang.Object
-
- com.identityworksllc.iiq.common.logging.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SlicingRewritePolicy.SlicingRewriteContextConfig
-
Constructor Summary
Constructors Constructor Description SlicingRewritePolicy(String substring, String regex, SlicingRewritePolicy.SlicingRewriteContextConfig contextConfig)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SlicingRewritePolicy
createSlicingPolicy(String regex, String substring, int startChars, int endChars, int contextChars)
The log4j2 factory method for creating one of these log event processorsQueue<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.org.apache.logging.log4j.core.LogEvent
rewrite(org.apache.logging.log4j.core.LogEvent source)
-
-
-
Constructor Detail
-
SlicingRewritePolicy
public SlicingRewritePolicy(String substring, String regex, SlicingRewritePolicy.SlicingRewriteContextConfig contextConfig)
-
-
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 anysubstring
- The substring to use, if anystartChars
- The number of characters to log from the start of the stringendChars
- The number of characters to log from the end of the stringcontextChars
- 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 interfaceorg.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
-
-