[ 
https://issues.apache.org/jira/browse/LOG4J2-2067?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16199531#comment-16199531
 ] 

Gary Gregory edited comment on LOG4J2-2067 at 10/10/17 11:03 PM:
-----------------------------------------------------------------

Would you be able to provide a unit test we can run that breaks without this 
patch?



was (Author: garydgregory):
Would you be able to provide a unit test we can run that breaks with this patch?


> Using PatternSelectors breaks header printing in PatternLayout
> --------------------------------------------------------------
>
>                 Key: LOG4J2-2067
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2067
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts, Pattern Converters
>    Affects Versions: 2.8.2, 2.9.0
>            Reporter: Paul Burrowes
>
> Using a config of
> {code}
> <?xml version="1.0" ?>
> <Configuration name="LOG4j2-1964 demo" status="ERROR">
>   <Appenders>
>     <Console name="consoleLog" target="SYSTEM_ERR">
>       <PatternLayout pattern="%msg{nolookups}%n%throwable{none}"/>
>     </Console>
>     <RollingFile name="fooAppender" fileName="foo.log" 
> filePattern="foo.log.%i">
>       <PatternLayout header="log file started%n">
>         <MarkerPatternSelector defaultPattern="%d{yyyy-MM-dd HH:mm:ss.SSSZ} 
> %msg{nolookups}%n">
>           <PatternMatch key="Trace" pattern="%d{yyyy-MM-dd HH:mm:ss.SSSZ} 
> TRACER %msg{nolookups}%n"/>
>         </MarkerPatternSelector>
>       </PatternLayout>
>       <SizeBasedTriggeringPolicy size="10MB"/>
>     </RollingFile>
>   </Appenders>
>   <Loggers>
>     <Root level="INFO">
>       <AppenderRef ref="consoleLog"/>
>       <AppenderRef ref="fooAppender"/>
>     </Root>
>   </Loggers>
> </Configuration>
> {code}
> the header is expected to be formatted according to the pattern configured 
> but instead the output is 
> {code}
> 2017-10-09 14:25:12.072+1300
> 2017-10-09 14:25:12.143+1300 using interpolation and a throwable 
> java.lang.NullPointerException
> java.lang.NullPointerException: null
>         at leliel.Main.main(Main.java:51) [Log4j2-testing/:?]
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.7.0_79]
>         at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
> ~[?:1.7.0_79]
>         at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.7.0_79]
>         at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_79]
>         at 
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 
> [idea_rt.jar:?]
> 2017-10-09 14:25:12.151+1300 throwable only
> {code}
> The fix appears to simply be to not provide the PatternSelector to the header 
> and footer Serializer builders.
> {code}
> diff --git 
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
>  
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
> index e4440eb9b..39042081f 100644
> --- 
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
> +++ 
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
> @@ -108,7 +108,7 @@ public final class PatternLayout extends 
> AbstractStringLayout {
>                  newSerializerBuilder()
>                          .setConfiguration(config)
>                          .setReplace(replace)
> -                        .setPatternSelector(patternSelector)
> +                        .setPatternSelector(null)
>                          .setAlwaysWriteExceptions(alwaysWriteExceptions)
>                          .setDisableAnsi(disableAnsi)
>                          .setNoConsoleNoAnsi(noConsoleNoAnsi)
> @@ -117,7 +117,7 @@ public final class PatternLayout extends 
> AbstractStringLayout {
>                  newSerializerBuilder()
>                          .setConfiguration(config)
>                          .setReplace(replace)
> -                        .setPatternSelector(patternSelector)
> +                        .setPatternSelector(null)
>                          .setAlwaysWriteExceptions(alwaysWriteExceptions)
>                          .setDisableAnsi(disableAnsi)
>                          .setNoConsoleNoAnsi(noConsoleNoAnsi)
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to