Package net.logstash.logback.pattern
Class AbstractJsonPatternParser<Event>
java.lang.Object
net.logstash.logback.pattern.AbstractJsonPatternParser<Event>
- Type Parameters:
Event
- - type of the event (ILoggingEvent, IAccessEvent)
- Direct Known Subclasses:
AccessEventJsonPatternParser
,LoggingEventJsonPatternParser
Parser that takes a JSON pattern, resolves all the conversion specifiers and returns an instance
of NodeWriter that, when its write() method is invoked, produces JSON defined by the parsed pattern.
- Author:
- Dmitry Andrianov
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
protected static class
protected static class
protected class
protected static class
protected class
static class
protected static class
protected static class
protected static interface
protected class
protected static class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
Pattern used to parse and detectAbstractJsonPatternParser.Operation
in a string. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addOperation
(String name, AbstractJsonPatternParser.Operation<?> operation) Register a newAbstractJsonPatternParser.Operation
and bind it to the givenname
.protected PatternLayoutAdapter<Event>
buildLayout
(String format) Initialize a PatternLayout with the supplied format and throw anIllegalArgumentException
if the format is invalid.protected abstract PatternLayoutBase<Event>
Create a PatternLayout instance of the appropriate type.boolean
Whentrue
, fields whose values are considered empty will be omitted from JSON output.protected ValueGetter<Event,
String> makeLayoutValueGetter
(String data) Parse a JSON pattern and produce the correspondingNodeWriter
.void
setOmitEmptyFields
(boolean omitEmptyFields) Whentrue
, fields whose values are considered empty will be omitted from JSON output.
-
Field Details
-
OPERATION_PATTERN
Pattern used to parse and detectAbstractJsonPatternParser.Operation
in a string. An operation starts with a #, followed by a name and a pair of {} with possible arguments in between.
-
-
Method Details
-
addOperation
Register a newAbstractJsonPatternParser.Operation
and bind it to the givenname
.- Parameters:
name
- the name of the operationoperation
- theAbstractJsonPatternParser.Operation
instance
-
makeLayoutValueGetter
-
buildLayout
Initialize a PatternLayout with the supplied format and throw anIllegalArgumentException
if the format is invalid.- Parameters:
format
- the pattern layout format- Returns:
- a configured and started
PatternLayoutAdapter
instance around the supplied format - Throws:
IllegalArgumentException
- if the supplied format is not a valid PatternLayout
-
createLayout
Create a PatternLayout instance of the appropriate type. The returned instance will be further configured with the context and appropriate pattern then started.- Returns:
- an unstarted
PatternLayoutBase
instance
-
parse
public NodeWriter<Event> parse(String pattern) throws AbstractJsonPatternParser.JsonPatternException Parse a JSON pattern and produce the correspondingNodeWriter
. Returns null if the pattern is invalid, null or empty. An error status is logged when the pattern is invalid and parsing failed.- Parameters:
pattern
- the JSON pattern to parse- Returns:
- a
NodeWriter
configured according to the pattern - Throws:
AbstractJsonPatternParser.JsonPatternException
- denotes an invalid pattern
-
isOmitEmptyFields
public boolean isOmitEmptyFields()Whentrue
, fields whose values are considered empty will be omitted from JSON output.- Returns:
true
if fields with empty values are omitted from JSON output
-
setOmitEmptyFields
public void setOmitEmptyFields(boolean omitEmptyFields) Whentrue
, fields whose values are considered empty will be omitted from JSON output.- Parameters:
omitEmptyFields
- whether fields with empty value should be omitted or not
-