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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Surendar Chandra
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Ralph Goers
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Surendar Chandra
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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]