You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Martin Frydl (JIRA)" <ji...@apache.org> on 2014/07/09 10:30:06 UTC
[jira] [Created] (LOG4J2-705) Async logger loses thread context
stack for events
Martin Frydl created LOG4J2-705:
-----------------------------------
Summary: Async logger loses thread context stack for events
Key: LOG4J2-705
URL: https://issues.apache.org/jira/browse/LOG4J2-705
Project: Log4j 2
Issue Type: Bug
Components: Core
Affects Versions: 2.0-rc2
Reporter: Martin Frydl
I've enabled the async logger and created some log message with values in thread context stack. However, the logged message does not contain any of these items.
Looking at the sources, it seems that AsyncLogger.logMessage() needs to clone the stack instead of using ThreadContext.getImmutableStack() (line 260). This is because getImmutableStack() method returns the same stack as original - getting the real one from thread local storage. So when passed to another thread (as async does), the same stack "looks" into different thread and returns empty list. It is even possible to break this "immutable" stack when you create your own appender and use ThreadContext.push() in append() method. This will affect the message being logged.
Simple solution is to replace getImmutableStack() method in AsyncLogger.logMessage() (line 260) with ThreadContext.cloneStack(). But I'm not sure if this is the right way.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org