Description
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.
Attachments
Issue Links
- links to