You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Surendar Chandra <su...@rubrik.com> on 2020/02/20 19:37:09 UTC

Accessing ThreadContext via "$${ctx:ndc}" vs "${ctx:ndc}"

I'm building a JSON log by using something like this in my xml config:

<KeyValuePair key="ndc" value="$${ctx:ndc}"/>

If I use a single $, for one particular value, the value seems to be
stuck at a constant. Other variables are fine. If I use a double $,
then it seems to work in all scenarios. I guess I should be using $$
but why is it flaky with a single $. Documentation states "During
initial configuration processing the first '$' will be removed.". In
that case I'd expect it to be {ctx:ndc} and not some other string.

Thanks

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


Re: Accessing ThreadContext via "$${ctx:ndc}" vs "${ctx:ndc}"

Posted by Surendar Chandra <su...@rubrik.com>.
Thanks Ralph. That is what I see most of the time except sometimes it
shows "ndc":"JobFetcher" where that string JobFetcher never changes
(even though we update the value in code). Since we also set
   <Configuration status="WARN" monitorInterval="30">
one way to unwedge the system is to "touch" the xml file. Setting it
to $${ctx:ndc} seems to do the right thing but I am not sure why it is
flaky with ${ctx:ndc}. I'd have expected the behavior to be consistent
(whether correct or not). Couldn't figure it out by looking at the
code either.

Thanks

On Thu, Feb 20, 2020 at 1:27 PM Ralph Goers <ra...@dslextreme.com> wrote:
>
> When a value doesn’t exist and you don’t specify a default value then the value of the variable string is itself. So If you code ${ctx:ndc} and there is no value for that you will see ${ctx:ndc} in the output.  Whenever StrSubstitutor finds a variable of the form $${ctx:ndc} it will simply strip the leading $ and you will get ${ctx:ndc}.
>
> Ralph
>
> > On Feb 20, 2020, at 12:37 PM, Surendar Chandra <su...@rubrik.com> wrote:
> >
> > I'm building a JSON log by using something like this in my xml config:
> >
> > <KeyValuePair key="ndc" value="$${ctx:ndc}"/>
> >
> > If I use a single $, for one particular value, the value seems to be
> > stuck at a constant. Other variables are fine. If I use a double $,
> > then it seems to work in all scenarios. I guess I should be using $$
> > but why is it flaky with a single $. Documentation states "During
> > initial configuration processing the first '$' will be removed.". In
> > that case I'd expect it to be {ctx:ndc} and not some other string.
> >
> > Thanks
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Re: Accessing ThreadContext via "$${ctx:ndc}" vs "${ctx:ndc}"

Posted by Ralph Goers <ra...@dslextreme.com>.
When a value doesn’t exist and you don’t specify a default value then the value of the variable string is itself. So If you code ${ctx:ndc} and there is no value for that you will see ${ctx:ndc} in the output.  Whenever StrSubstitutor finds a variable of the form $${ctx:ndc} it will simply strip the leading $ and you will get ${ctx:ndc}.

Ralph

> On Feb 20, 2020, at 12:37 PM, Surendar Chandra <su...@rubrik.com> wrote:
> 
> I'm building a JSON log by using something like this in my xml config:
> 
> <KeyValuePair key="ndc" value="$${ctx:ndc}"/>
> 
> If I use a single $, for one particular value, the value seems to be
> stuck at a constant. Other variables are fine. If I use a double $,
> then it seems to work in all scenarios. I guess I should be using $$
> but why is it flaky with a single $. Documentation states "During
> initial configuration processing the first '$' will be removed.". In
> that case I'd expect it to be {ctx:ndc} and not some other string.
> 
> Thanks
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



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