[ https://issues.apache.org/jira/browse/LOG4J2-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16182311#comment-16182311 ]
Barna Zsombor Klara commented on LOG4J2-1216: --------------------------------------------- I think I ran into this issue recently and it seem it is still broken in 2.9.2-SNAPSHOT. I tried the following patterns: {code} %notEmpty{%X{var}} - %maxLen{%X{var}}{2} - %notEmpty{ %maxLen{%X{var}} } {code} and my output was: {code} 2017-09-27 12:03:45,684 main ERROR Incorrect number of options on maxLength: expected 2 received 0: [] 2017-09-27 12:03:45,687 main ERROR Unrecognized conversion specifier [maxLen] starting at position 16 in conversion pattern. value - va - } {code} The patterns work individually, but not when they are nested. If I take a look at the unit test does your offer to merge it still stand [~jvz]? > Nested pattern layout options broken > ------------------------------------ > > Key: LOG4J2-1216 > URL: https://issues.apache.org/jira/browse/LOG4J2-1216 > Project: Log4j 2 > Issue Type: Bug > Components: Pattern Converters > Affects Versions: 2.4.1 > Reporter: Thies Wellpott > Labels: easyfix > > Parsing the "deeply" nested PatternLayout > {code} > %maxLen{[XXX, ${hostName}, ${web:contextPath}] %p: %c{1} - %m%notEmpty{ > =>%ex{short}}}{160} > {code} > (with %maxLen being a custom Converter) > results in wrong parsing. > Patternparser.extractOptions() gets the nesting wrong. > Solution: > {code} > private static int extractOptions(final String pattern, final int start, > final List<String> options) { > int i = start; > while (i < pattern.length() && pattern.charAt(i) == '{') { > i++; // skip opening "{" > final int begin = i; // position of first real char > int depth = 1; // already inside one level > while (depth > 0 && i < pattern.length()) { > char c = pattern.charAt(i); > if (c == '{') { > depth++; > } else if (c == '}') { > depth--; > // TODO(?) maybe escaping of { and } with \ or % > } > i++; > } // while > if (depth > 0) { // option not closed, continue with pattern > on opening "{" > return begin-1; > } > options.add(pattern.substring(begin, i-1)); > } // while > return i; > } > {code} > This should also be faster than the current implementation because the > pattern ist only walked once, not multiple times with indexOf(). > (LOG4J2-107 is a similar but old bug) -- This message was sent by Atlassian JIRA (v6.4.14#64029)