Display text when thread context is empty

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Display text when thread context is empty

christian
Hi all,

with the pattern /%X{userNumber}/ I am able to display a value I stored
in the thread context.

Is there any possibilty to display an alternative value if nothing was
found and/or an empty value was stored under the key I'm suing (in this
case /userNumber/).


Thanks and best regards,

Christian

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Display text when thread context is empty

Matt Sicker
There's the %notEmpty{} pattern which only outputs its pattern if all its
variables are not empty. If you want a default value, then perhaps combine
that with %replace{%notEmpty{%X{userNumber}}}{^$}{fallback value} or
something similar. You shouldn't need the %notEmpty{} bit if you don't add
anything around the pattern variables (e.g., parenthesis).

On 22 March 2017 at 13:33, Christian <[hidden email]> wrote:

> Hi all,
>
> with the pattern /%X{userNumber}/ I am able to display a value I stored in
> the thread context.
>
> Is there any possibilty to display an alternative value if nothing was
> found and/or an empty value was stored under the key I'm suing (in this
> case /userNumber/).
>
>
> Thanks and best regards,
>
> Christian
>
>


--
Matt Sicker <[hidden email]>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Display text when thread context is empty

Ralph Goers
In reply to this post by christian
If userNumber does not exist in the ThreadContext then nothing will be included in the display.  I am not aware that we have implemented any way to specify a default value for this, but with the Data Injection stuff that was added a few releases ago it might be possible.

Ralph

> On Mar 22, 2017, at 11:33 AM, Christian <[hidden email]> wrote:
>
> Hi all,
>
> with the pattern /%X{userNumber}/ I am able to display a value I stored in the thread context.
>
> Is there any possibilty to display an alternative value if nothing was found and/or an empty value was stored under the key I'm suing (in this case /userNumber/).
>
>
> Thanks and best regards,
>
> Christian
>



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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Display text when thread context is empty

christian
Thanks Matt and Ralph!

I also thought if it is possible to use the %replace pattern for this
purpose. I think I will give this a try.


@Ralph: What do you mean with "Data Injection stuff"? Do you have any
link a documentation with information about this?


Best regards,

Christian


Am 22.03.2017 um 19:55 schrieb Ralph Goers:

> If userNumber does not exist in the ThreadContext then nothing will be included in the display.  I am not aware that we have implemented any way to specify a default value for this, but with the Data Injection stuff that was added a few releases ago it might be possible.
>
> Ralph
>
>> On Mar 22, 2017, at 11:33 AM, Christian <[hidden email]> wrote:
>>
>> Hi all,
>>
>> with the pattern /%X{userNumber}/ I am able to display a value I stored in the thread context.
>>
>> Is there any possibilty to display an alternative value if nothing was found and/or an empty value was stored under the key I'm suing (in this case /userNumber/).
>>
>>
>> Thanks and best regards,
>>
>> Christian
>>
>
>
> ---------------------------------------------------------------------
> 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
|  
Report Content as Inappropriate

Re: Display text when thread context is empty

Matt Sicker
I believe he's referencing this:

https://logging.apache.org/log4j/2.x/manual/extending.html#Custom_ContextDataInjector

On 22 March 2017 at 14:48, Christian <[hidden email]> wrote:

> Thanks Matt and Ralph!
>
> I also thought if it is possible to use the %replace pattern for this
> purpose. I think I will give this a try.
>
>
> @Ralph: What do you mean with "Data Injection stuff"? Do you have any link
> a documentation with information about this?
>
>
> Best regards,
>
> Christian
>
>
>
> Am 22.03.2017 um 19:55 schrieb Ralph Goers:
>
>> If userNumber does not exist in the ThreadContext then nothing will be
>> included in the display.  I am not aware that we have implemented any way
>> to specify a default value for this, but with the Data Injection stuff that
>> was added a few releases ago it might be possible.
>>
>> Ralph
>>
>> On Mar 22, 2017, at 11:33 AM, Christian <[hidden email]> wrote:
>>>
>>> Hi all,
>>>
>>> with the pattern /%X{userNumber}/ I am able to display a value I stored
>>> in the thread context.
>>>
>>> Is there any possibilty to display an alternative value if nothing was
>>> found and/or an empty value was stored under the key I'm suing (in this
>>> case /userNumber/).
>>>
>>>
>>> Thanks and best regards,
>>>
>>> Christian
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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]
>
>


--
Matt Sicker <[hidden email]>
Loading...