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

ASF GitHub Bot commented on LOG4J2-2368:
----------------------------------------

Github user garydgregory commented on a diff in the pull request:

    https://github.com/apache/logging-log4j2/pull/189#discussion_r201176090
  
    --- Diff: 
log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
 ---
    @@ -114,6 +115,10 @@ public B setHeaderSerializer(final Serializer 
headerSerializer) {
          * @return a {@code StringBuilder}
          */
         protected static StringBuilder getStringBuilder() {
    +        if (AbstractLogger.getRecursionDepth() > 1) { // LOG4J2-2368
    --- End diff --
    
    Curious and somewhat unrelated: Why isn't the recursion depth a Integer or 
AtomicInteger?


> Outputs wrong message when used within overridden Throwable method
> ------------------------------------------------------------------
>
>                 Key: LOG4J2-2368
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2368
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8.1, 2.11.0
>            Reporter: Taisuke Tashiro
>            Assignee: Carter Kozak
>            Priority: Major
>
> When a message A is logged with Throwable object and if message B is logged 
> within the Throwable object's method, message A is lost and message B is 
> logged instead.
> Following is a code example to recreate the issue:
> {{Logger loggerA = LogManager.getLogger("A");}}
> {{Logger loggerB = LogManager.getLogger("B");}}
> {{Throwable throwable =}}
> {{    new Throwable() {}}
> {{        public String getMessage() {}}
> {{            loggerB.debug("MESSAGE B");}}
> {{            return "message";}}
> {{        }}}
> {{    };}}
> {{loggerA.debug("MESSEGE A", throwable);}}
> "MESSAGE A" should be logged to loggerA but "MESSAGE B" is logged instead.
> Cause of this problem is reuse of StringBuilder instance within the execution 
> thread in org.apache.logging.log4j.core.layout.AbstractStringLayout class. 
> While processing loggerA, getMessage() is called by 
> org.apache.logging.log4j.core.impl.ThrowableProxy to obtain throwable object 
> information and the content of StringBuilder is changed by loggerB.
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to