Class PatternParser
java.lang.Object
org.apache.logging.log4j.core.pattern.PatternParser
Most of the work of the
PatternLayout
class is delegated to the
PatternParser class.
It is this class that parses conversion patterns and creates a chained list of PatternConverters
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
The states the parser can be in while parsing the pattern. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private final Configuration
private final Map
<String, Class<PatternConverter>> private static final int
(package private) static final String
private static final char
Escape character for format specifier.private static final Logger
(package private) static final String
-
Constructor Summary
ConstructorsConstructorDescriptionPatternParser
(String converterKey) Constructor.PatternParser
(Configuration config, String converterKey, Class<?> expected) Constructor.PatternParser
(Configuration config, String converterKey, Class<?> expectedClass, Class<?> filterClass) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
areValidNewInstanceParameters
(Class<?>[] parameterTypes) LOG4J2-2564: Returns true if all method parameters are valid for injection.private PatternConverter
createConverter
(String converterId, StringBuilder currentLiteral, Map<String, Class<PatternConverter>> rules, List<String> options, boolean disableAnsi, boolean noConsoleNoAnsi) Creates a new PatternConverter.private static int
extractConverter
(char lastChar, String pattern, int start, StringBuilder convBuf, StringBuilder currentLiteral) Extracts the converter identifier found at the given start position.private static int
extractOptions
(String pattern, int start, List<String> options) Extract options.private int
finalizeConverter
(char c, String pattern, int start, StringBuilder currentLiteral, FormattingInfo formattingInfo, Map<String, Class<PatternConverter>> rules, List<PatternConverter> patternConverters, List<FormattingInfo> formattingInfos, boolean disableAnsi, boolean noConsoleNoAnsi, boolean convertBackslashes) Processes a format specifier sequence.private LogEventPatternConverter
literalPattern
(String literal, boolean convertBackslashes) void
parse
(String pattern, List<PatternConverter> patternConverters, List<FormattingInfo> formattingInfos, boolean noConsoleNoAnsi, boolean convertBackslashes) Parse a format specifier.void
parse
(String pattern, List<PatternConverter> patternConverters, List<FormattingInfo> formattingInfos, boolean disableAnsi, boolean noConsoleNoAnsi, boolean convertBackslashes) Parse a format specifier.
-
Field Details
-
DISABLE_ANSI
- See Also:
-
NO_CONSOLE_NO_ANSI
- See Also:
-
ESCAPE_CHAR
private static final char ESCAPE_CHAREscape character for format specifier.- See Also:
-
LOGGER
-
BUF_SIZE
private static final int BUF_SIZE- See Also:
-
DECIMAL
private static final int DECIMAL- See Also:
-
config
-
converterRules
-
-
Constructor Details
-
PatternParser
Constructor.- Parameters:
converterKey
- The type of converters that will be used.
-
PatternParser
Constructor.- Parameters:
config
- The current Configuration ornull
.converterKey
- The key to lookup the converters.expected
- The expected base Class of each Converter ornull
.
-
PatternParser
public PatternParser(Configuration config, String converterKey, Class<?> expectedClass, Class<?> filterClass) Constructor.- Parameters:
config
- The current Configuration ornull
.converterKey
- The key to lookup the converters.expectedClass
- The expected base Class of each Converter ornull
.filterClass
- Filter the returned plugins after calling the plugin manager, can benull
.
-
-
Method Details
-
parse
-
parse
public List<PatternFormatter> parse(String pattern, boolean alwaysWriteExceptions, boolean noConsoleNoAnsi) -
parse
public List<PatternFormatter> parse(String pattern, boolean alwaysWriteExceptions, boolean disableAnsi, boolean noConsoleNoAnsi) -
extractConverter
private static int extractConverter(char lastChar, String pattern, int start, StringBuilder convBuf, StringBuilder currentLiteral) Extracts the converter identifier found at the given start position.After this function returns, the variable i will point to the first char after the end of the converter identifier.
If i points to a char which is not a character acceptable at the start of a unicode identifier, the value null is returned.
- Parameters:
lastChar
- last processed character.pattern
- format string.start
- current index into pattern format.convBuf
- buffer to receive conversion specifier.currentLiteral
- literal to be output in case format specifier in unrecognized.- Returns:
- position in pattern after converter.
-
extractOptions
Extract options.- Parameters:
pattern
- conversion pattern.start
- start of options.options
- array to receive extracted options- Returns:
- position in pattern after options.
-
parse
public void parse(String pattern, List<PatternConverter> patternConverters, List<FormattingInfo> formattingInfos, boolean noConsoleNoAnsi, boolean convertBackslashes) Parse a format specifier.- Parameters:
pattern
- pattern to parse.patternConverters
- list to receive pattern converters.formattingInfos
- list to receive field specifiers corresponding to pattern converters.noConsoleNoAnsi
- do not do not output ANSI escape codes ifSystem.console()
convertBackslashes
- iftrue
, backslash characters are treated as escape characters and character sequences like "\" followed by "t" (backslash+t) are converted to special characters like '\t' (tab).
-
parse
public void parse(String pattern, List<PatternConverter> patternConverters, List<FormattingInfo> formattingInfos, boolean disableAnsi, boolean noConsoleNoAnsi, boolean convertBackslashes) Parse a format specifier.- Parameters:
pattern
- pattern to parse.patternConverters
- list to receive pattern converters.formattingInfos
- list to receive field specifiers corresponding to pattern converters.disableAnsi
- do not output ANSI escape codesnoConsoleNoAnsi
- do not do not output ANSI escape codes ifSystem.console()
convertBackslashes
- iftrue
, backslash characters are treated as escape characters and character sequences like "\" followed by "t" (backslash+t) are converted to special characters like '\t' (tab).
-
createConverter
private PatternConverter createConverter(String converterId, StringBuilder currentLiteral, Map<String, Class<PatternConverter>> rules, List<String> options, boolean disableAnsi, boolean noConsoleNoAnsi) Creates a new PatternConverter.- Parameters:
converterId
- converterId.currentLiteral
- literal to be used if converter is unrecognized or following converter if converterId contains extra characters.rules
- map of stock pattern converters keyed by format specifier.options
- converter options.disableAnsi
- do not output ANSI escape codesnoConsoleNoAnsi
- do not do not output ANSI escape codes ifSystem.console()
- Returns:
- converter or null.
-
areValidNewInstanceParameters
LOG4J2-2564: Returns true if all method parameters are valid for injection. -
finalizeConverter
private int finalizeConverter(char c, String pattern, int start, StringBuilder currentLiteral, FormattingInfo formattingInfo, Map<String, Class<PatternConverter>> rules, List<PatternConverter> patternConverters, List<FormattingInfo> formattingInfos, boolean disableAnsi, boolean noConsoleNoAnsi, boolean convertBackslashes) Processes a format specifier sequence.- Parameters:
c
- initial character of format specifier.pattern
- conversion patternstart
- current position in conversion pattern.currentLiteral
- current literal.formattingInfo
- current field specifier.rules
- map of stock pattern converters keyed by format specifier.patternConverters
- list to receive parsed pattern converter.formattingInfos
- list to receive corresponding field specifier.disableAnsi
- do not output ANSI escape codesnoConsoleNoAnsi
- do not do not output ANSI escape codes ifSystem.console()
convertBackslashes
- iftrue
, backslash characters are treated as escape characters and character sequences like "\" followed by "t" (backslash+t) are converted to special characters like '\t' (tab).- Returns:
- position after format specifier sequence.
-
literalPattern
-