logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Thomas (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1010) Possibility to set ThreadContext values in calls to Logger method
Date Thu, 23 Jun 2016 07:57:16 GMT

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

Greg Thomas commented on LOG4J2-1010:
-------------------------------------

On the assumption that (generally) a thread that is processing a request, or even part of
a request, may wish to log more than once, how about enhancing ThreadContext with a state
getter and setter; the state is essentially a combination of {{getImmutableStack()}} and {{getImmutableContext()}};
you could retrieve the current state of the ThreadContext at any point in time, and then use
that current ThreadContext to that state at any other point to set the state to that point;
giving something like ...

{code}
final ThreadContext.State state = ThreadContext.getState()
new Thread(new Runnable() {
        public void run() {
            ThreadContext.setState(state);
            logger.debug("Starting processing");
            ...
            logger.debug("Ending processing");
            ThreadContext.clear();
        }
    }).start();
{code}

(OK, so that example could more easily be implemented using {{isThreadContextMapInheritable}},
but the above could be extended to use thread pools, unlike {{isThreadContextMapInheritable}}.

> Possibility to set ThreadContext values in calls to Logger method
> -----------------------------------------------------------------
>
>                 Key: LOG4J2-1010
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1010
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: 2.2
>            Reporter: Mikael Ståldal
>         Attachments: properties.patch
>
>
> It would be useful to have some logging methods in the Logger interface to set ThreadContext
values for a single log message only.
> In an asynchronous environment, using ThreadContext as currently defined is not so useful
since JVM threads might not be coupled to the logical flow of the application.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message