logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lars-Fredrik Smedberg <itsme...@gmail.com>
Subject Re: Question on accessing the threadcontext in pattern vs lookup
Date Sun, 11 Apr 2021 16:16:11 GMT
Hi

Thanks all for the answers.

I actually did some debugging and changed to the thread context data on the
log event around the time for the first reply (when i saw that the log
event was constructed before passing it to the async logger). The reason
for using the lookup and not only %X is that is does more than just pass
the value through (at least for some keys). The lookup also provides values
not based upon the thread context so it's also for consistency reasons
towards the internal users/developers.

Preciate everyone's time, thanks
Best regards
LF

On Sat, Apr 10, 2021, 22:24 Ralph Goers <ralph.goers@dslextreme.com> wrote:

> Your assumption is correct, but there is a way to avoid the problem. The
> issue is that, as one might expect, the ThreadContext is thread specific.
> So when the pattern is resolved it will be on the thread where the event is
> to be written, not the thread that called the logging method.
>
> You can avoid this problem by not using the ThreadContext directly.
> Instead, get the context data out of the LogEvent. It will contain the
> ThreadContext data at the time the LogEvent was created. However, that
> would give you exactly the same thing %X does, so what is the point?
>
> Ralph
>
> > On Apr 9, 2021, at 9:00 AM, Lars-Fredrik Smedberg <itsmeden@gmail.com>
> wrote:
> >
> > Hi!
> >
> > We are using different appenders with a pattern layout that both read
> > values from ThreadContext using %X and through a custom lookup that
> > internally access the ThreadContext
> >
> > If we use a pattern such as "%X{testkey} $${m:testkey} %m" (the lookup
> > assigned to prefix m access the same key from the ThreadContext) and then
> > use our appender in an AsyncLogger then we get the correct value for the
> > %X{testkey} but not for $${m:testkey}.
> >
> > I assume the message is formatted on the caller thread but that the
> lookup
> > part of the pattern is resolved on the async thread since it does not
> seem
> > to find the key in the ThreadContext inside our lookup class?
> >
> > Is the above the root cause to our problem? Is there a way around this?
> We
> > really would like to use our custom lookup that use ThreadContext with
> > async loggers.
> >
> > Any help would be greatly apreciated
> > Best regards
> > LF
> >
> > --
> > Med vänlig hälsning / Best regards
> >
> > Lars-Fredrik Smedberg
> >
> > STATEMENT OF CONFIDENTIALITY:
> > The information contained in this electronic message and any
> > attachments to this message are intended for the exclusive use of the
> > address(es) and may contain confidential or privileged information. If
> > you are not the intended recipient, please notify Lars-Fredrik Smedberg
> > immediately at itsmeden@gmail.com, and destroy all copies of this
> > message and any attachments.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message