Package org.frankframework.logging
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
- limit log message length
- apply global masking
- apply local (thread-wise) masking
- Author:
- Murat Kaan Meral
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface overridesAutoCloseable.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_SIZEFields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGERFields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedIbisMaskingLayout(org.apache.logging.log4j.core.config.Configuration config, Charset charset) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddToGlobalReplace(String regex) static voidaddToGlobalReplace(Pattern regex) static voidstatic voidClear all thread-local hide-regexes.static intstatic Stringstatic Collection<Pattern> Collection of regex strings to hide locally, meaning for specific threads/adapters.static StringmaskSensitiveInfo(String message) pushToThreadLocalReplace(Pattern pattern) Push a hide-regex pattern to the ThreadLocal replace-hideregex stack and return aIbisMaskingLayout.HideRegexContextthat can be closed to pop the pattern from the stack again.protected abstract StringserializeEvent(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 voidsetMaxLength(int maxLength) static voidsetMoreMessageString(String moreMessage) static voidsetThreadLocalReplace(Collection<Pattern> hideRegexCollection) Replace all thread-local hideRegexes.final StringtoSerializable(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, trimToMaxSizeMethods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
encode, getConfiguration, getContentFormat, markEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.core.layout.Encoder
encodeMethods 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
-
maskSensitiveInfo
-
serializeEvent
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
-
setMoreMessageString
-
addToGlobalReplace
-
addToGlobalReplace
-
getGlobalReplace
-
clearGlobalReplace
public static void clearGlobalReplace() -
setThreadLocalReplace
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
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 aIbisMaskingLayout.HideRegexContextthat 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.HideRegexContextthat can be closed to remove above pattern from the stack again.
-