Class IbisMaskingLayout

java.lang.Object
org.apache.logging.log4j.core.layout.AbstractLayout<String>
org.apache.logging.log4j.core.layout.AbstractStringLayout
org.frankframework.logging.IbisMaskingLayout
All Implemented Interfaces:
org.apache.logging.log4j.core.impl.LocationAware, org.apache.logging.log4j.core.Layout<String>, org.apache.logging.log4j.core.layout.Encoder<org.apache.logging.log4j.core.LogEvent>, org.apache.logging.log4j.core.StringLayout
Direct Known Subclasses:
IbisPatternLayout

public abstract class IbisMaskingLayout extends org.apache.logging.log4j.core.layout.AbstractStringLayout
This is a wrapper for Log4j2 layouts. It enables us to:
- limit log message length
- apply global masking
- apply local (thread-wise) masking
Author:
Murat Kaan Meral
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Interface overrides AutoCloseable.close() to remove the exception so this can be used in a try-with-resources without having to handle any exceptions, however does not need to add any extra methods.

    Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout

    org.apache.logging.log4j.core.layout.AbstractStringLayout.Builder<B extends org.apache.logging.log4j.core.layout.AbstractStringLayout.Builder<B>>, org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer, org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
  • Field Summary

    Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout

    DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE

    Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout

    configuration, eventCount, footer, header, LOGGER

    Fields inherited from interface org.apache.logging.log4j.core.Layout

    ELEMENT_TYPE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    IbisMaskingLayout(org.apache.logging.log4j.core.config.Configuration config, Charset charset)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
     
    static void
     
    static void
     
    static void
    Clear all thread-local hide-regexes.
    static Set<Pattern>
     
    static int
     
    static String
     
    Collection of regex strings to hide locally, meaning for specific threads/adapters.
    static String
     
    Push a hide-regex pattern to the ThreadLocal replace-hideregex stack and return a IbisMaskingLayout.HideRegexContext that can be closed to pop the pattern from the stack again.
    protected abstract String
    serializeEvent(org.apache.logging.log4j.core.LogEvent event)
    Mutable LogEvent which masks messages using global and local regex strings, and shortens the message to a maximum length, if necessary.
    static void
    setMaxLength(int maxLength)
     
    static void
     
    static void
    Replace all thread-local hideRegexes.
    final String
    toSerializable(org.apache.logging.log4j.core.LogEvent logEvent)
     

    Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout

    getBytes, getCharset, getContentType, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, requiresLocation, serializeToBytes, serializeToString, toByteArray, trimToMaxSize

    Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout

    encode, getConfiguration, getContentFormat, markEvent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.logging.log4j.core.layout.Encoder

    encode

    Methods inherited from interface org.apache.logging.log4j.core.Layout

    getContentFormat
  • Constructor Details

    • IbisMaskingLayout

      protected IbisMaskingLayout(org.apache.logging.log4j.core.config.Configuration config, Charset charset)
      Parameters:
      config -
      charset - defaults to the system's default
  • Method Details

    • toSerializable

      public final String toSerializable(org.apache.logging.log4j.core.LogEvent logEvent)
    • maskSensitiveInfo

      public static String maskSensitiveInfo(String message)
    • serializeEvent

      protected abstract String serializeEvent(org.apache.logging.log4j.core.LogEvent event)
      Mutable LogEvent which masks messages using global and local regex strings, and shortens the message to a maximum length, if necessary.
      Parameters:
      event - Event to be serialized to a String.
      Returns:
      Serialized and masked event.
    • setMaxLength

      public static void setMaxLength(int maxLength)
    • getMaxLength

      public static int getMaxLength()
    • getMoreMessageString

      public static String getMoreMessageString()
    • setMoreMessageString

      public static void setMoreMessageString(String moreMessage)
    • addToGlobalReplace

      public static void addToGlobalReplace(String regex)
    • addToGlobalReplace

      public static void addToGlobalReplace(Pattern regex)
    • getGlobalReplace

      public static Set<Pattern> getGlobalReplace()
    • clearGlobalReplace

      public static void clearGlobalReplace()
    • setThreadLocalReplace

      public static void setThreadLocalReplace(@Nullable Collection<Pattern> hideRegexCollection)
      Replace all thread-local hideRegexes. Always clears the current stack, even if the new collection is null or empty. This method should be used to initialize the stack of hideregexes at the start of a new thread when there might be hideregexes to be carried over from a calling thread.
      Parameters:
      hideRegexCollection - Collection of new hideRegexes. Can be null or empty.
      See Also:
    • getThreadLocalReplace

      @Nullable public static Collection<Pattern> getThreadLocalReplace()
      Collection of regex strings to hide locally, meaning for specific threads/adapters. Can return null when not used/initialized!
    • clearThreadLocalReplace

      public static void clearThreadLocalReplace()
      Clear all thread-local hide-regexes.
    • pushToThreadLocalReplace

      @Nonnull public static IbisMaskingLayout.HideRegexContext pushToThreadLocalReplace(@Nullable Pattern pattern)
      Push a hide-regex pattern to the ThreadLocal replace-hideregex stack and return a IbisMaskingLayout.HideRegexContext that can be closed to pop the pattern from the stack again. This is meant to be used in try-with-resources construct.
      Parameters:
      pattern - Pattern used to find strings in loglines that need to be hidden.
      Returns:
      IbisMaskingLayout.HideRegexContext that can be closed to remove above pattern from the stack again.