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
Modifier and TypeClassDescriptionstatic interface
Interface 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_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
ModifierConstructorDescriptionprotected
IbisMaskingLayout
(org.apache.logging.log4j.core.config.Configuration config, Charset charset) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addToGlobalReplace
(String regex) static void
addToGlobalReplace
(Pattern regex) static void
static void
Clear all thread-local hide-regexes.static int
static String
static Collection<Pattern>
Collection of regex strings to hide locally, meaning for specific threads/adapters.static String
maskSensitiveInfo
(String message) pushToThreadLocalReplace
(Pattern pattern) Push a hide-regex pattern to the ThreadLocal replace-hideregex stack and return aIbisMaskingLayout.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
setMoreMessageString
(String moreMessage) static void
setThreadLocalReplace
(Collection<Pattern> hideRegexCollection) 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
-
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.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.
-