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 Oliver Flege <of...@vwd.com> on 2013/10/01 10:13:51 UTC

Re: default value for missing key in mdc

> $${mdc:request_id} in a pattern should cause the request_id to be evaluated on every event.
> 

thanks a lot, $${ctx:request_id} seems to do the trick

however, the computation of the default value is quite complex as it always involves
a variable substitution, and I cannot use conversion specifiers with $$ as I can with %X

Would you consider accepting a patch that adds support for slf4j-like default values
in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?

Regards,
Oliver



> 
>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com> wrote:
>>
>> ok, this works for ${...} expressions in the configuration, but I don't see how it would
>> apply to pattern evaluation. To simplify and rephrase my original question:
>>
>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>>
>> is it possible to define a default value that will be printed
>> if the thread never executed ThreadContext.put("REQUEST_ID", "XYZ")?
>>
>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>> will only be evaluated when the configuration is parsed.
>>
>> Oliver
>>
>>> Yes, it supports default values. Specify them as properties at the beginning of your configuration. Then when you specify something like ${sys:foo} if foo is not defined as a system property the default value will be used,
>>>
>>> Ralph
>>>
>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege <of...@vwd.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am considering to switch from slf4j/logback to log4j2;
>>>>
>>>> in slf4j/logback, I can specify a default value for a missing mdc entry
>>>> like this:
>>>>
>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0} - %m%n</pattern>
>>>>
>>>> which would print "-" if mdc.get("FOO") is null (the ":-" separates
>>>> the key and the default value).
>>>>
>>>> Having a defined number of tokens/fields at the beginning of the log message
>>>> makes it easier to process it with awk/cut etc.
>>>>
>>>>
>>>> Does log4j support default values? - I could not find any hint in the documentation
>>>>
>>>>
>>>>
>>>> Regards,
>>>> Oliver
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>>
>> -- 
>> Oliver Flege
>> Senior Software Engineer | vwd group
>>
>> vwd Vereinigte Wirtschaftsdienste AG
>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>> oflege@vwd.com | www.vwd.com
>> ______________________________________________________________
>>
>> vwd Vereinigte Wirtschaftsdienste AG
>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>> Handelsregister: AG Frankfurt am Main HRB 81011
>> Vorstand: Dr. Ralf Kauther
>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>> ____________________________________________________________
>>
>> ---------------------------------------------------------------------
>> 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
> 


-- 
Oliver Flege
Senior Software Engineer | vwd group

vwd Vereinigte Wirtschaftsdienste AG
Stiftsplatz 6/7 | 67655 Kaiserslautern
Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
oflege@vwd.com | www.vwd.com
______________________________________________________________

vwd Vereinigte Wirtschaftsdienste AG
Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
Handelsregister: AG Frankfurt am Main HRB 81011
Vorstand: Dr. Ralf Kauther
Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
____________________________________________________________

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


Re: default value for missing key in mdc

Posted by Woonsan Ko <wo...@yahoo.com>.
I uploaded a patch for the issue (to allow inline default value setting in general after the variable name and the delimiter):
- https://issues.apache.org/jira/browse/LOG4J2-419

Please take a review.

Cheers,

Woonsan





> On Wednesday, October 9, 2013 4:19 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> > Please remember that mine is just one opinion, but I am fine with that.  I guess 
> if no default value is provided this way then it can still fall back to looking 
> in the properties map.
> 
> Ralph
> 
> 
> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
> 
>>  Hi Ralph,
>> 
>> 
>>  I have something related to this improvement idea.
>>  I have thought it might be a bit more useful and flexible to allow default 
> value in the variable expression itself.
>>  For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, 
> etc.
>>  This generic feature has been included in StrSubstitutor of commons-lang3 
> with the following issue:
>>  - https://issues.apache.org/jira/browse/LANG-893
>> 
>>  I understand Oliver's patch should work more efficiently for map 
> pattern converters, but the goodness of the feature with LANG-893 is we can use 
> it more widely whenever used in look ups.
>> 
>>  I know StrSubstitutor in log4j2 added more operations to deal with LogEvent 
> argument, so I can create a patch to include the feature of LANG-893 if it is 
> useful for others.
>>  Also, Oliver's patch won't conflict with this patch.
>> 
>>  What do you think?
>> 
>>  Kind regards,
>> 
>>  Woonsan
>> 
>> 
>>>  On Tuesday, October 1, 2013 9:21 AM, Ralph Goers 
> <rg...@apache.org> wrote:
>>>>  Patches are always welcome!
>>> 
>>>  Ralph
>>> 
>>>  On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
>>> 
>>>>>  $${mdc:request_id} in a pattern should cause the 
> request_id to be 
>>>  evaluated on every event.
>>>> 
>>>>  thanks a lot, $${ctx:request_id} seems to do the trick
>>>> 
>>>>  however, the computation of the default value is quite complex as 
> it always 
>>>  involves
>>>>  a variable substitution, and I cannot use conversion specifiers 
> with $$ as 
>>>  I can with %X
>>>> 
>>>>  Would you consider accepting a patch that adds support for 
> slf4j-like 
>>>  default values
>>>>  in %X{key} and %K{key}, s.th. like 
> %X{key:-defaultValue} ?
>>>> 
>>>>  Regards,
>>>>  Oliver
>>>> 
>>>> 
>>>> 
>>>>> 
>>>>>>  On Sep 30, 2013, at 8:04 AM, Oliver Flege 
> <of...@vwd.com> 
>>>  wrote:
>>>>>> 
>>>>>>  ok, this works for ${...} expressions in the 
> configuration, 
>>>  but I don't see how it would
>>>>>>  apply to pattern evaluation. To simplify and rephrase my 
> original 
>>>  question:
>>>>>> 
>>>>>>  Given a pattern layout with a pattern like:  
> %X{REQUEST_ID}
>>>>>> 
>>>>>>  is it possible to define a default value that will be 
> printed
>>>>>>  if the thread never executed 
>>>  ThreadContext.put("REQUEST_ID", "XYZ")?
>>>>>> 
>>>>>>  I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but 
> that
>>>>>>  will only be evaluated when the configuration is parsed.
>>>>>> 
>>>>>>  Oliver
>>>>>> 
>>>>>>>  Yes, it supports default values. Specify them as 
> properties at 
>>>  the beginning of your configuration. Then when you specify something 
> like 
>>>  ${sys:foo} if foo is not defined as a system property the default 
> value 
>>>  will be used,
>>>>>>> 
>>>>>>>  Ralph
>>>>>>> 
>>>>>>>>  On Sep 30, 2013, at 3:30 AM, Oliver Flege 
>>>  <of...@vwd.com> wrote:
>>>>>>>> 
>>>>>>>>  Hi,
>>>>>>>> 
>>>>>>>>  I am considering to switch from slf4j/logback to 
> log4j2;
>>>>>>>> 
>>>>>>>>  in slf4j/logback, I can specify a default value for 
> a 
>>>  missing mdc entry
>>>>>>>>  like this:
>>>>>>>> 
>>>>>>>>  <pattern>%d{HH:mm:ss} %X{FOO:--} 
> %c{0} 
>>>  - %m%n</pattern>
>>>>>>>> 
>>>>>>>>  which would print "-" if 
> mdc.get("FOO") 
>>>  is null (the ":-" separates
>>>>>>>>  the key and the default value).
>>>>>>>> 
>>>>>>>>  Having a defined number of tokens/fields at the 
> beginning 
>>>  of the log message
>>>>>>>>  makes it easier to process it with awk/cut etc.
>>>>>>>> 
>>>>>>>> 
>>>>>>>>  Does log4j support default values? - I could not 
> find any 
>>>  hint in the documentation
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>>  Regards,
>>>>>>>>  Oliver
>>>>>>>> 
>>>>>>>> 
>>>  ---------------------------------------------------------------------
>>>>>>>>  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
>>>>>> 
>>>>>> 
>>>>>>  -- 
>>>>>>  Oliver Flege
>>>>>>  Senior Software Engineer | vwd group
>>>>>> 
>>>>>>  vwd Vereinigte Wirtschaftsdienste AG
>>>>>>  Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>>>  Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>>>  oflege@vwd.com | www.vwd.com
>>>>>> 
> ______________________________________________________________
>>>>>> 
>>>>>>  vwd Vereinigte Wirtschaftsdienste AG
>>>>>>  Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt 
> am Main
>>>>>>  Handelsregister: AG Frankfurt am Main HRB 81011
>>>>>>  Vorstand: Dr. Ralf Kauther
>>>>>>  Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> 
>>> 
>>>>>> 
> ____________________________________________________________
>>>>>> 
>>>>>> 
>>>  ---------------------------------------------------------------------
>>>>>>  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
>>>> 
>>>> 
>>>>  -- 
>>>>  Oliver Flege
>>>>  Senior Software Engineer | vwd group
>>>> 
>>>>  vwd Vereinigte Wirtschaftsdienste AG
>>>>  Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>  Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>  oflege@vwd.com | www.vwd.com
>>>>  ______________________________________________________________
>>>> 
>>>>  vwd Vereinigte Wirtschaftsdienste AG
>>>>  Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>>>  Handelsregister: AG Frankfurt am Main HRB 81011
>>>>  Vorstand: Dr. Ralf Kauther
>>>>  Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>>>  ____________________________________________________________
>>>> 
>>>> 
> ---------------------------------------------------------------------
>>>>  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
>> 
> 
> 
> ---------------------------------------------------------------------
> 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: default value for missing key in mdc

Posted by Remko Popma <re...@gmail.com>.
Yes. Anyone can read existing issues, but to add or comment you need to
create an account.

Best regards,
Remko

On Thursday, October 10, 2013, Jonathan Willis wrote:

> i am able to view the jira page, and i have been there before, but i don't
> see how to add an issue. Do i need credentials to log in?
>
>
> On Wed, Oct 9, 2013 at 5:43 PM, Remko Popma <re...@gmail.com> wrote:
>
> > Oh. Sorry. Here you are:
> > http://logging.apache.org/log4j/2.x/issue-tracking.html
> >
> > Sent from my iPhone
> >
> > > On 2013/10/10, at 8:25, Jonathan Willis <qu...@gmail.com>
> > wrote:
> > >
> > > How do you create a jira ticket? I looked for where i could but i didnt
> > see
> > > anywhere that said add issue
> > >> On Oct 9, 2013 4:47 PM, "Remko Popma" <re...@gmail.com> wrote:
> > >>
> > >> Jonathan,
> > >> Would you mind raising a JIRA ticket for the issue you're reporting?
> > >> That makes it easier for us to track and easier for you to attach
> config
> > >> files or image files. (The mailing list software may not like image
> file
> > >> attachments...)
> > >>
> > >> Best regards,
> > >> Remko
> > >>
> > >> Sent from my iPhone
> > >>
> > >>>> On 2013/10/10, at 6:15, Jonathan Willis <qu...@gmail.com>
> > >>> wrote:
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>> On Wed, Oct 9, 2013 at 3:05 PM, Ralph Goers <
> > ralph.goers@dslextreme.com>
> > >> wrote:
> > >>>> Can you provide your lookup source?
> > >>>>
> > >>>>
> > >>>> On Oct 9, 2013, at 1:22 PM, Jonathan Willis <
> quicksilversly@gmail.com
> > >
> > >> wrote:
> > >>>>
> > >>
> >
> http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
> > >>>>>
> > >>>>>
> > >>>>> On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <
> > >> ralph.goers@dslextreme.com>wrote:
> > >>>>>
> > >>>>>> Please remember that mine is just one opinion, but I am fine with
> > >> that.  I
> > >>>>>> guess if no default value is provided this way then it can still
> > >> fall back
> > >>>>>> to looking in the properties map.
> > >>>>>>
> > >>>>>> Ralph
> > >>>>>>
> > >>>>>>
> > >>>>>>> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com>
> > wrote:
> > >>>>>>>
> > >>>>>>> Hi Ralph,
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> I have something related to this improvement idea.
> > >>>>>>> I have thought it might be a bit more useful and flexible to
> allow
> > >>>>>> default value in the variable expression itself.
> > >>>>>>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2},
> etc.
> > >>>>>>> This generic feature has been included in StrSubstitutor of
> > >>>>>> commons-lang3 with the following issue:
> > >>>>>>> - https://issues.apache.org/jira/browse/LANG-893
> > >>>>>>>
> > >>>>>>> I understand Oliver's patch should work more efficiently for map
> > >> pattern
> > >>>>>> converters, but the goodness of the feature with LANG-893 is we
> can
> > >> use it
> > >>>>>> more widely whenever used in look ups.
> > >>>>>>>
> > >>>>>>> I know StrSubstitutor in log4j2 added more operations to deal
> with
>

Re: default value for missing key in mdc

Posted by Jonathan Willis <qu...@gmail.com>.
i am able to view the jira page, and i have been there before, but i don't
see how to add an issue. Do i need credentials to log in?


On Wed, Oct 9, 2013 at 5:43 PM, Remko Popma <re...@gmail.com> wrote:

> Oh. Sorry. Here you are:
> http://logging.apache.org/log4j/2.x/issue-tracking.html
>
> Sent from my iPhone
>
> > On 2013/10/10, at 8:25, Jonathan Willis <qu...@gmail.com>
> wrote:
> >
> > How do you create a jira ticket? I looked for where i could but i didnt
> see
> > anywhere that said add issue
> >> On Oct 9, 2013 4:47 PM, "Remko Popma" <re...@gmail.com> wrote:
> >>
> >> Jonathan,
> >> Would you mind raising a JIRA ticket for the issue you're reporting?
> >> That makes it easier for us to track and easier for you to attach config
> >> files or image files. (The mailing list software may not like image file
> >> attachments...)
> >>
> >> Best regards,
> >> Remko
> >>
> >> Sent from my iPhone
> >>
> >>>> On 2013/10/10, at 6:15, Jonathan Willis <qu...@gmail.com>
> >>> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>> On Wed, Oct 9, 2013 at 3:05 PM, Ralph Goers <
> ralph.goers@dslextreme.com>
> >> wrote:
> >>>> Can you provide your lookup source?
> >>>>
> >>>>
> >>>> On Oct 9, 2013, at 1:22 PM, Jonathan Willis <quicksilversly@gmail.com
> >
> >> wrote:
> >>>>
> >>
> http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
> >>>>>
> >>>>>
> >>>>> On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <
> >> ralph.goers@dslextreme.com>wrote:
> >>>>>
> >>>>>> Please remember that mine is just one opinion, but I am fine with
> >> that.  I
> >>>>>> guess if no default value is provided this way then it can still
> >> fall back
> >>>>>> to looking in the properties map.
> >>>>>>
> >>>>>> Ralph
> >>>>>>
> >>>>>>
> >>>>>>> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com>
> wrote:
> >>>>>>>
> >>>>>>> Hi Ralph,
> >>>>>>>
> >>>>>>>
> >>>>>>> I have something related to this improvement idea.
> >>>>>>> I have thought it might be a bit more useful and flexible to allow
> >>>>>> default value in the variable expression itself.
> >>>>>>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
> >>>>>>> This generic feature has been included in StrSubstitutor of
> >>>>>> commons-lang3 with the following issue:
> >>>>>>> - https://issues.apache.org/jira/browse/LANG-893
> >>>>>>>
> >>>>>>> I understand Oliver's patch should work more efficiently for map
> >> pattern
> >>>>>> converters, but the goodness of the feature with LANG-893 is we can
> >> use it
> >>>>>> more widely whenever used in look ups.
> >>>>>>>
> >>>>>>> I know StrSubstitutor in log4j2 added more operations to deal with
> >>>>>> LogEvent argument, so I can create a patch to include the feature of
> >>>>>> LANG-893 if it is useful for others.
> >>>>>>> Also, Oliver's patch won't conflict with this patch.
> >>>>>>>
> >>>>>>> What do you think?
> >>>>>>>
> >>>>>>> Kind regards,
> >>>>>>>
> >>>>>>> Woonsan
> >>>>>>>
> >>>>>>>
> >>>>>>>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <
> >> rgoers@apache.org>
> >>>>>> wrote:
> >>>>>>>>> Patches are always welcome!
> >>>>>>>>
> >>>>>>>> Ralph
> >>>>>>>>
> >>>>>>>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
> >>>>>>>>
> >>>>>>>>>> $${mdc:request_id} in a pattern should cause the request_id to
> be
> >>>>>>>> evaluated on every event.
> >>>>>>>>>
> >>>>>>>>> thanks a lot, $${ctx:request_id} seems to do the trick
> >>>>>>>>>
> >>>>>>>>> however, the computation of the default value is quite complex as
> >> it
> >>>>>> always
> >>>>>>>> involves
> >>>>>>>>> a variable substitution, and I cannot use conversion specifiers
> >> with
> >>>>>> $$ as
> >>>>>>>> I can with %X
> >>>>>>>>>
> >>>>>>>>> Would you consider accepting a patch that adds support for
> >> slf4j-like
> >>>>>>>> default values
> >>>>>>>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
> >>>>>>>>>
> >>>>>>>>> Regards,
> >>>>>>>>> Oliver
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
> >>>>>>>> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> ok, this works for ${...} expressions in the configuration,
> >>>>>>>> but I don't see how it would
> >>>>>>>>>>> apply to pattern evaluation. To simplify and rephrase my
> >> original
> >>>>>>>> question:
> >>>>>>>>>>>
> >>>>>>>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
> >>>>>>>>>>>
> >>>>>>>>>>> is it possible to define a default value that will be printed
> >>>>>>>>>>> if the thread never executed
> >>>>>>>> ThreadContext.put("REQUEST_ID", "XYZ")?
> >>>>>>>>>>>
> >>>>>>>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
> >>>>>>>>>>> will only be evaluated when the configuration is parsed.
> >>>>>>>>>>>
> >>>>>>>>>>> Oliver
> >>>>>>>>>>>
> >>>>>>>>>>>> Yes, it supports default values. Specify them as properties at
> >>>>>>>> the beginning of your configuration. Then when you specify
> >> something
> >>>>>> like
> >>>>>>>> ${sys:foo} if foo is not defined as a system property the default
> >> value
> >>>>>>>> will be used,
> >>>>>>>>>>>>
> >>>>>>>>>>>> Ralph
> >>>>>>>>>>>>
> >>>>>>>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
> >>>>>>>> <of...@vwd.com> wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Hi,
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> I am considering to switch from slf4j/logback to log4j2;
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> in slf4j/logback, I can specify a default value for a
> >>>>>>>> missing mdc entry
> >>>>>>>>>>>>> like this:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
> >>>>>>>> - %m%n</pattern>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> which would print "-" if mdc.get("FOO")
> >>>>>>>> is null (the ":-" separates
> >>>>>>>>>>>>> the key and the default value).
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Having a defined number of tokens/fields at the beginning
> >>>>>>>> of the log message
> >>>>>>>>>>>>> makes it easier to process it with awk/cut etc.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Does log4j support default values? - I could not find any
> >>>>>>>> hint in the documentation
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Regards,
> >>>>>>>>>>>>> Oliver
> >> ---------------------------------------------------------------------
> >>>>>>>>>>>>> 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
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> --
> >>>>>>>>>>> Oliver Flege
> >>>>>>>>>>> Senior Software Engineer | vwd group
> >>>>>>>>>>>
> >>>>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>>>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >>>>>>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >>>>>>>>>>> oflege@vwd.com | www.vwd.com
> >>>>>>>>>>> ______________________________________________________________
> >>>>>>>>>>>
> >>>>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>>>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am
> >> Main
> >>>>>>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >>>>>>>>>>> Vorstand: Dr. Ralf Kauther
> >>>>>>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >>>>>>>>
> >>>>>>>>>>> ____________________________________________________________
> >> ---------------------------------------------------------------------
> >>>>>>>>>>> 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
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> --
> >>>>>>>>> Oliver Flege
> >>>>>>>>> Senior Software Engineer | vwd group
> >>>>>>>>>
> >>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >>>>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >>>>>>>>> oflege@vwd.com | www.vwd.com
> >>>>>>>>> ______________________________________________________________
> >>>>>>>>>
> >>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am
> Main
> >>>>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >>>>>>>>> Vorstand: Dr. Ralf Kauther
> >>>>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >>>>>>>>> ____________________________________________________________
> >> ---------------------------------------------------------------------
> >>>>>>>>> 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
> >>>>>>
> >>>>>>
> >>>>>>
> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Jonathan Willis
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>
> >>>
> >>>
> >>> --
> >>> Jonathan Willis
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Jonathan Willis

Re: default value for missing key in mdc

Posted by Remko Popma <re...@gmail.com>.
Oh. Sorry. Here you are:
http://logging.apache.org/log4j/2.x/issue-tracking.html

Sent from my iPhone

> On 2013/10/10, at 8:25, Jonathan Willis <qu...@gmail.com> wrote:
> 
> How do you create a jira ticket? I looked for where i could but i didnt see
> anywhere that said add issue
>> On Oct 9, 2013 4:47 PM, "Remko Popma" <re...@gmail.com> wrote:
>> 
>> Jonathan,
>> Would you mind raising a JIRA ticket for the issue you're reporting?
>> That makes it easier for us to track and easier for you to attach config
>> files or image files. (The mailing list software may not like image file
>> attachments...)
>> 
>> Best regards,
>> Remko
>> 
>> Sent from my iPhone
>> 
>>>> On 2013/10/10, at 6:15, Jonathan Willis <qu...@gmail.com>
>>> wrote:
>>> 
>>> 
>>> 
>>> 
>>> 
>>>> On Wed, Oct 9, 2013 at 3:05 PM, Ralph Goers <ra...@dslextreme.com>
>> wrote:
>>>> Can you provide your lookup source?
>>>> 
>>>> 
>>>> On Oct 9, 2013, at 1:22 PM, Jonathan Willis <qu...@gmail.com>
>> wrote:
>>>> 
>> http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
>>>>> 
>>>>> 
>>>>> On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <
>> ralph.goers@dslextreme.com>wrote:
>>>>> 
>>>>>> Please remember that mine is just one opinion, but I am fine with
>> that.  I
>>>>>> guess if no default value is provided this way then it can still
>> fall back
>>>>>> to looking in the properties map.
>>>>>> 
>>>>>> Ralph
>>>>>> 
>>>>>> 
>>>>>>> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
>>>>>>> 
>>>>>>> Hi Ralph,
>>>>>>> 
>>>>>>> 
>>>>>>> I have something related to this improvement idea.
>>>>>>> I have thought it might be a bit more useful and flexible to allow
>>>>>> default value in the variable expression itself.
>>>>>>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
>>>>>>> This generic feature has been included in StrSubstitutor of
>>>>>> commons-lang3 with the following issue:
>>>>>>> - https://issues.apache.org/jira/browse/LANG-893
>>>>>>> 
>>>>>>> I understand Oliver's patch should work more efficiently for map
>> pattern
>>>>>> converters, but the goodness of the feature with LANG-893 is we can
>> use it
>>>>>> more widely whenever used in look ups.
>>>>>>> 
>>>>>>> I know StrSubstitutor in log4j2 added more operations to deal with
>>>>>> LogEvent argument, so I can create a patch to include the feature of
>>>>>> LANG-893 if it is useful for others.
>>>>>>> Also, Oliver's patch won't conflict with this patch.
>>>>>>> 
>>>>>>> What do you think?
>>>>>>> 
>>>>>>> Kind regards,
>>>>>>> 
>>>>>>> Woonsan
>>>>>>> 
>>>>>>> 
>>>>>>>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <
>> rgoers@apache.org>
>>>>>> wrote:
>>>>>>>>> Patches are always welcome!
>>>>>>>> 
>>>>>>>> Ralph
>>>>>>>> 
>>>>>>>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
>>>>>>>> 
>>>>>>>>>> $${mdc:request_id} in a pattern should cause the request_id to be
>>>>>>>> evaluated on every event.
>>>>>>>>> 
>>>>>>>>> thanks a lot, $${ctx:request_id} seems to do the trick
>>>>>>>>> 
>>>>>>>>> however, the computation of the default value is quite complex as
>> it
>>>>>> always
>>>>>>>> involves
>>>>>>>>> a variable substitution, and I cannot use conversion specifiers
>> with
>>>>>> $$ as
>>>>>>>> I can with %X
>>>>>>>>> 
>>>>>>>>> Would you consider accepting a patch that adds support for
>> slf4j-like
>>>>>>>> default values
>>>>>>>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
>>>>>>>>> 
>>>>>>>>> Regards,
>>>>>>>>> Oliver
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
>>>>>>>> wrote:
>>>>>>>>>>> 
>>>>>>>>>>> ok, this works for ${...} expressions in the configuration,
>>>>>>>> but I don't see how it would
>>>>>>>>>>> apply to pattern evaluation. To simplify and rephrase my
>> original
>>>>>>>> question:
>>>>>>>>>>> 
>>>>>>>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>>>>>>>>>>> 
>>>>>>>>>>> is it possible to define a default value that will be printed
>>>>>>>>>>> if the thread never executed
>>>>>>>> ThreadContext.put("REQUEST_ID", "XYZ")?
>>>>>>>>>>> 
>>>>>>>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>>>>>>>>>>> will only be evaluated when the configuration is parsed.
>>>>>>>>>>> 
>>>>>>>>>>> Oliver
>>>>>>>>>>> 
>>>>>>>>>>>> Yes, it supports default values. Specify them as properties at
>>>>>>>> the beginning of your configuration. Then when you specify
>> something
>>>>>> like
>>>>>>>> ${sys:foo} if foo is not defined as a system property the default
>> value
>>>>>>>> will be used,
>>>>>>>>>>>> 
>>>>>>>>>>>> Ralph
>>>>>>>>>>>> 
>>>>>>>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
>>>>>>>> <of...@vwd.com> wrote:
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>> 
>>>>>>>>>>>>> I am considering to switch from slf4j/logback to log4j2;
>>>>>>>>>>>>> 
>>>>>>>>>>>>> in slf4j/logback, I can specify a default value for a
>>>>>>>> missing mdc entry
>>>>>>>>>>>>> like this:
>>>>>>>>>>>>> 
>>>>>>>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
>>>>>>>> - %m%n</pattern>
>>>>>>>>>>>>> 
>>>>>>>>>>>>> which would print "-" if mdc.get("FOO")
>>>>>>>> is null (the ":-" separates
>>>>>>>>>>>>> the key and the default value).
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Having a defined number of tokens/fields at the beginning
>>>>>>>> of the log message
>>>>>>>>>>>>> makes it easier to process it with awk/cut etc.
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Does log4j support default values? - I could not find any
>>>>>>>> hint in the documentation
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>> Oliver
>> ---------------------------------------------------------------------
>>>>>>>>>>>>> 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
>>>>>>>>>>> 
>>>>>>>>>>> 
>>>>>>>>>>> --
>>>>>>>>>>> Oliver Flege
>>>>>>>>>>> Senior Software Engineer | vwd group
>>>>>>>>>>> 
>>>>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>>>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>>>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>>>>>>>> oflege@vwd.com | www.vwd.com
>>>>>>>>>>> ______________________________________________________________
>>>>>>>>>>> 
>>>>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>>>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am
>> Main
>>>>>>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>>>>>>>>>> Vorstand: Dr. Ralf Kauther
>>>>>>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>>>>>>> 
>>>>>>>>>>> ____________________________________________________________
>> ---------------------------------------------------------------------
>>>>>>>>>>> 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
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> --
>>>>>>>>> Oliver Flege
>>>>>>>>> Senior Software Engineer | vwd group
>>>>>>>>> 
>>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>>>>>> oflege@vwd.com | www.vwd.com
>>>>>>>>> ______________________________________________________________
>>>>>>>>> 
>>>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>>>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>>>>>>>> Vorstand: Dr. Ralf Kauther
>>>>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>>>>>>>> ____________________________________________________________
>> ---------------------------------------------------------------------
>>>>>>>>> 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
>>>>>> 
>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>>> 
>>>>> 
>>>>> --
>>>>> Jonathan Willis
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>>> 
>>> 
>>> --
>>> Jonathan Willis
>> 

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


Re: default value for missing key in mdc

Posted by Jonathan Willis <qu...@gmail.com>.
How do you create a jira ticket? I looked for where i could but i didnt see
anywhere that said add issue
On Oct 9, 2013 4:47 PM, "Remko Popma" <re...@gmail.com> wrote:

> Jonathan,
> Would you mind raising a JIRA ticket for the issue you're reporting?
> That makes it easier for us to track and easier for you to attach config
> files or image files. (The mailing list software may not like image file
> attachments...)
>
> Best regards,
> Remko
>
> Sent from my iPhone
>
> > On 2013/10/10, at 6:15, Jonathan Willis <qu...@gmail.com>
> wrote:
> >
> >
> >
> >
> >
> >> On Wed, Oct 9, 2013 at 3:05 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
> >> Can you provide your lookup source?
> >>
> >>
> >> On Oct 9, 2013, at 1:22 PM, Jonathan Willis <qu...@gmail.com>
> wrote:
> >>
> >> >
> http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
> >> >
> >> >
> >> > On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <
> ralph.goers@dslextreme.com>wrote:
> >> >
> >> >> Please remember that mine is just one opinion, but I am fine with
> that.  I
> >> >> guess if no default value is provided this way then it can still
> fall back
> >> >> to looking in the properties map.
> >> >>
> >> >> Ralph
> >> >>
> >> >>
> >> >> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
> >> >>
> >> >>> Hi Ralph,
> >> >>>
> >> >>>
> >> >>> I have something related to this improvement idea.
> >> >>> I have thought it might be a bit more useful and flexible to allow
> >> >> default value in the variable expression itself.
> >> >>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
> >> >>> This generic feature has been included in StrSubstitutor of
> >> >> commons-lang3 with the following issue:
> >> >>> - https://issues.apache.org/jira/browse/LANG-893
> >> >>>
> >> >>> I understand Oliver's patch should work more efficiently for map
> pattern
> >> >> converters, but the goodness of the feature with LANG-893 is we can
> use it
> >> >> more widely whenever used in look ups.
> >> >>>
> >> >>> I know StrSubstitutor in log4j2 added more operations to deal with
> >> >> LogEvent argument, so I can create a patch to include the feature of
> >> >> LANG-893 if it is useful for others.
> >> >>> Also, Oliver's patch won't conflict with this patch.
> >> >>>
> >> >>> What do you think?
> >> >>>
> >> >>> Kind regards,
> >> >>>
> >> >>> Woonsan
> >> >>>
> >> >>>
> >> >>>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <
> rgoers@apache.org>
> >> >> wrote:
> >> >>>>> Patches are always welcome!
> >> >>>>
> >> >>>> Ralph
> >> >>>>
> >> >>>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
> >> >>>>
> >> >>>>>> $${mdc:request_id} in a pattern should cause the request_id to be
> >> >>>> evaluated on every event.
> >> >>>>>
> >> >>>>> thanks a lot, $${ctx:request_id} seems to do the trick
> >> >>>>>
> >> >>>>> however, the computation of the default value is quite complex as
> it
> >> >> always
> >> >>>> involves
> >> >>>>> a variable substitution, and I cannot use conversion specifiers
> with
> >> >> $$ as
> >> >>>> I can with %X
> >> >>>>>
> >> >>>>> Would you consider accepting a patch that adds support for
> slf4j-like
> >> >>>> default values
> >> >>>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
> >> >>>>>
> >> >>>>> Regards,
> >> >>>>> Oliver
> >> >>>>>
> >> >>>>>
> >> >>>>>
> >> >>>>>>
> >> >>>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
> >> >>>> wrote:
> >> >>>>>>>
> >> >>>>>>> ok, this works for ${...} expressions in the configuration,
> >> >>>> but I don't see how it would
> >> >>>>>>> apply to pattern evaluation. To simplify and rephrase my
> original
> >> >>>> question:
> >> >>>>>>>
> >> >>>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
> >> >>>>>>>
> >> >>>>>>> is it possible to define a default value that will be printed
> >> >>>>>>> if the thread never executed
> >> >>>> ThreadContext.put("REQUEST_ID", "XYZ")?
> >> >>>>>>>
> >> >>>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
> >> >>>>>>> will only be evaluated when the configuration is parsed.
> >> >>>>>>>
> >> >>>>>>> Oliver
> >> >>>>>>>
> >> >>>>>>>> Yes, it supports default values. Specify them as properties at
> >> >>>> the beginning of your configuration. Then when you specify
> something
> >> >> like
> >> >>>> ${sys:foo} if foo is not defined as a system property the default
> value
> >> >>>> will be used,
> >> >>>>>>>>
> >> >>>>>>>> Ralph
> >> >>>>>>>>
> >> >>>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
> >> >>>> <of...@vwd.com> wrote:
> >> >>>>>>>>>
> >> >>>>>>>>> Hi,
> >> >>>>>>>>>
> >> >>>>>>>>> I am considering to switch from slf4j/logback to log4j2;
> >> >>>>>>>>>
> >> >>>>>>>>> in slf4j/logback, I can specify a default value for a
> >> >>>> missing mdc entry
> >> >>>>>>>>> like this:
> >> >>>>>>>>>
> >> >>>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
> >> >>>> - %m%n</pattern>
> >> >>>>>>>>>
> >> >>>>>>>>> which would print "-" if mdc.get("FOO")
> >> >>>> is null (the ":-" separates
> >> >>>>>>>>> the key and the default value).
> >> >>>>>>>>>
> >> >>>>>>>>> Having a defined number of tokens/fields at the beginning
> >> >>>> of the log message
> >> >>>>>>>>> makes it easier to process it with awk/cut etc.
> >> >>>>>>>>>
> >> >>>>>>>>>
> >> >>>>>>>>> Does log4j support default values? - I could not find any
> >> >>>> hint in the documentation
> >> >>>>>>>>>
> >> >>>>>>>>>
> >> >>>>>>>>>
> >> >>>>>>>>> Regards,
> >> >>>>>>>>> Oliver
> >> >>>>>>>>>
> >> >>>>>>>>>
> >> >>>>
> ---------------------------------------------------------------------
> >> >>>>>>>>> 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
> >> >>>>>>>
> >> >>>>>>>
> >> >>>>>>> --
> >> >>>>>>> Oliver Flege
> >> >>>>>>> Senior Software Engineer | vwd group
> >> >>>>>>>
> >> >>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >> >>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >> >>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >> >>>>>>> oflege@vwd.com | www.vwd.com
> >> >>>>>>> ______________________________________________________________
> >> >>>>>>>
> >> >>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >> >>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am
> Main
> >> >>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >> >>>>>>> Vorstand: Dr. Ralf Kauther
> >> >>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >> >>>>
> >> >>>>>>> ____________________________________________________________
> >> >>>>>>>
> >> >>>>>>>
> >> >>>>
> ---------------------------------------------------------------------
> >> >>>>>>> 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
> >> >>>>>
> >> >>>>>
> >> >>>>> --
> >> >>>>> Oliver Flege
> >> >>>>> Senior Software Engineer | vwd group
> >> >>>>>
> >> >>>>> vwd Vereinigte Wirtschaftsdienste AG
> >> >>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >> >>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >> >>>>> oflege@vwd.com | www.vwd.com
> >> >>>>> ______________________________________________________________
> >> >>>>>
> >> >>>>> vwd Vereinigte Wirtschaftsdienste AG
> >> >>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
> >> >>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >> >>>>> Vorstand: Dr. Ralf Kauther
> >> >>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >> >>>>> ____________________________________________________________
> >> >>>>>
> >> >>>>>
> ---------------------------------------------------------------------
> >> >>>>> 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
> >> >>>
> >> >>
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> > --
> >> > Jonathan Willis
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
> >
> > --
> > Jonathan Willis
> >
>

Re: default value for missing key in mdc

Posted by Remko Popma <re...@gmail.com>.
Jonathan,
Would you mind raising a JIRA ticket for the issue you're reporting?
That makes it easier for us to track and easier for you to attach config files or image files. (The mailing list software may not like image file attachments...)

Best regards,
Remko

Sent from my iPhone

> On 2013/10/10, at 6:15, Jonathan Willis <qu...@gmail.com> wrote:
> 
> 
> 
> 
> 
>> On Wed, Oct 9, 2013 at 3:05 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>> Can you provide your lookup source?
>> 
>> 
>> On Oct 9, 2013, at 1:22 PM, Jonathan Willis <qu...@gmail.com> wrote:
>> 
>> > http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
>> >
>> >
>> > On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <ra...@dslextreme.com>wrote:
>> >
>> >> Please remember that mine is just one opinion, but I am fine with that.  I
>> >> guess if no default value is provided this way then it can still fall back
>> >> to looking in the properties map.
>> >>
>> >> Ralph
>> >>
>> >>
>> >> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
>> >>
>> >>> Hi Ralph,
>> >>>
>> >>>
>> >>> I have something related to this improvement idea.
>> >>> I have thought it might be a bit more useful and flexible to allow
>> >> default value in the variable expression itself.
>> >>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
>> >>> This generic feature has been included in StrSubstitutor of
>> >> commons-lang3 with the following issue:
>> >>> - https://issues.apache.org/jira/browse/LANG-893
>> >>>
>> >>> I understand Oliver's patch should work more efficiently for map pattern
>> >> converters, but the goodness of the feature with LANG-893 is we can use it
>> >> more widely whenever used in look ups.
>> >>>
>> >>> I know StrSubstitutor in log4j2 added more operations to deal with
>> >> LogEvent argument, so I can create a patch to include the feature of
>> >> LANG-893 if it is useful for others.
>> >>> Also, Oliver's patch won't conflict with this patch.
>> >>>
>> >>> What do you think?
>> >>>
>> >>> Kind regards,
>> >>>
>> >>> Woonsan
>> >>>
>> >>>
>> >>>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <rg...@apache.org>
>> >> wrote:
>> >>>>> Patches are always welcome!
>> >>>>
>> >>>> Ralph
>> >>>>
>> >>>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
>> >>>>
>> >>>>>> $${mdc:request_id} in a pattern should cause the request_id to be
>> >>>> evaluated on every event.
>> >>>>>
>> >>>>> thanks a lot, $${ctx:request_id} seems to do the trick
>> >>>>>
>> >>>>> however, the computation of the default value is quite complex as it
>> >> always
>> >>>> involves
>> >>>>> a variable substitution, and I cannot use conversion specifiers with
>> >> $$ as
>> >>>> I can with %X
>> >>>>>
>> >>>>> Would you consider accepting a patch that adds support for slf4j-like
>> >>>> default values
>> >>>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
>> >>>>>
>> >>>>> Regards,
>> >>>>> Oliver
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>>>
>> >>>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
>> >>>> wrote:
>> >>>>>>>
>> >>>>>>> ok, this works for ${...} expressions in the configuration,
>> >>>> but I don't see how it would
>> >>>>>>> apply to pattern evaluation. To simplify and rephrase my original
>> >>>> question:
>> >>>>>>>
>> >>>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>> >>>>>>>
>> >>>>>>> is it possible to define a default value that will be printed
>> >>>>>>> if the thread never executed
>> >>>> ThreadContext.put("REQUEST_ID", "XYZ")?
>> >>>>>>>
>> >>>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>> >>>>>>> will only be evaluated when the configuration is parsed.
>> >>>>>>>
>> >>>>>>> Oliver
>> >>>>>>>
>> >>>>>>>> Yes, it supports default values. Specify them as properties at
>> >>>> the beginning of your configuration. Then when you specify something
>> >> like
>> >>>> ${sys:foo} if foo is not defined as a system property the default value
>> >>>> will be used,
>> >>>>>>>>
>> >>>>>>>> Ralph
>> >>>>>>>>
>> >>>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
>> >>>> <of...@vwd.com> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Hi,
>> >>>>>>>>>
>> >>>>>>>>> I am considering to switch from slf4j/logback to log4j2;
>> >>>>>>>>>
>> >>>>>>>>> in slf4j/logback, I can specify a default value for a
>> >>>> missing mdc entry
>> >>>>>>>>> like this:
>> >>>>>>>>>
>> >>>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
>> >>>> - %m%n</pattern>
>> >>>>>>>>>
>> >>>>>>>>> which would print "-" if mdc.get("FOO")
>> >>>> is null (the ":-" separates
>> >>>>>>>>> the key and the default value).
>> >>>>>>>>>
>> >>>>>>>>> Having a defined number of tokens/fields at the beginning
>> >>>> of the log message
>> >>>>>>>>> makes it easier to process it with awk/cut etc.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Does log4j support default values? - I could not find any
>> >>>> hint in the documentation
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Regards,
>> >>>>>>>>> Oliver
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>> ---------------------------------------------------------------------
>> >>>>>>>>> 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
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> --
>> >>>>>>> Oliver Flege
>> >>>>>>> Senior Software Engineer | vwd group
>> >>>>>>>
>> >>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>> >>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>> >>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>> >>>>>>> oflege@vwd.com | www.vwd.com
>> >>>>>>> ______________________________________________________________
>> >>>>>>>
>> >>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>> >>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>> >>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>> >>>>>>> Vorstand: Dr. Ralf Kauther
>> >>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>> >>>>
>> >>>>>>> ____________________________________________________________
>> >>>>>>>
>> >>>>>>>
>> >>>> ---------------------------------------------------------------------
>> >>>>>>> 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
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Oliver Flege
>> >>>>> Senior Software Engineer | vwd group
>> >>>>>
>> >>>>> vwd Vereinigte Wirtschaftsdienste AG
>> >>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>> >>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>> >>>>> oflege@vwd.com | www.vwd.com
>> >>>>> ______________________________________________________________
>> >>>>>
>> >>>>> vwd Vereinigte Wirtschaftsdienste AG
>> >>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>> >>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>> >>>>> Vorstand: Dr. Ralf Kauther
>> >>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>> >>>>> ____________________________________________________________
>> >>>>>
>> >>>>> ---------------------------------------------------------------------
>> >>>>> 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
>> >>>
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Jonathan Willis
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> 
> -- 
> Jonathan Willis
> 

Re: default value for missing key in mdc

Posted by Jonathan Willis <qu...@gmail.com>.
[image: Inline image 1]
[image: Inline image 2]


On Wed, Oct 9, 2013 at 3:05 PM, Ralph Goers <ra...@dslextreme.com>wrote:

> Can you provide your lookup source?
>
>
> On Oct 9, 2013, at 1:22 PM, Jonathan Willis <qu...@gmail.com>
> wrote:
>
> >
> http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
> >
> >
> > On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <ralph.goers@dslextreme.com
> >wrote:
> >
> >> Please remember that mine is just one opinion, but I am fine with that.
>  I
> >> guess if no default value is provided this way then it can still fall
> back
> >> to looking in the properties map.
> >>
> >> Ralph
> >>
> >>
> >> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
> >>
> >>> Hi Ralph,
> >>>
> >>>
> >>> I have something related to this improvement idea.
> >>> I have thought it might be a bit more useful and flexible to allow
> >> default value in the variable expression itself.
> >>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
> >>> This generic feature has been included in StrSubstitutor of
> >> commons-lang3 with the following issue:
> >>> - https://issues.apache.org/jira/browse/LANG-893
> >>>
> >>> I understand Oliver's patch should work more efficiently for map
> pattern
> >> converters, but the goodness of the feature with LANG-893 is we can use
> it
> >> more widely whenever used in look ups.
> >>>
> >>> I know StrSubstitutor in log4j2 added more operations to deal with
> >> LogEvent argument, so I can create a patch to include the feature of
> >> LANG-893 if it is useful for others.
> >>> Also, Oliver's patch won't conflict with this patch.
> >>>
> >>> What do you think?
> >>>
> >>> Kind regards,
> >>>
> >>> Woonsan
> >>>
> >>>
> >>>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <rg...@apache.org>
> >> wrote:
> >>>>> Patches are always welcome!
> >>>>
> >>>> Ralph
> >>>>
> >>>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
> >>>>
> >>>>>> $${mdc:request_id} in a pattern should cause the request_id to be
> >>>> evaluated on every event.
> >>>>>
> >>>>> thanks a lot, $${ctx:request_id} seems to do the trick
> >>>>>
> >>>>> however, the computation of the default value is quite complex as it
> >> always
> >>>> involves
> >>>>> a variable substitution, and I cannot use conversion specifiers with
> >> $$ as
> >>>> I can with %X
> >>>>>
> >>>>> Would you consider accepting a patch that adds support for slf4j-like
> >>>> default values
> >>>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
> >>>>>
> >>>>> Regards,
> >>>>> Oliver
> >>>>>
> >>>>>
> >>>>>
> >>>>>>
> >>>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
> >>>> wrote:
> >>>>>>>
> >>>>>>> ok, this works for ${...} expressions in the configuration,
> >>>> but I don't see how it would
> >>>>>>> apply to pattern evaluation. To simplify and rephrase my original
> >>>> question:
> >>>>>>>
> >>>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
> >>>>>>>
> >>>>>>> is it possible to define a default value that will be printed
> >>>>>>> if the thread never executed
> >>>> ThreadContext.put("REQUEST_ID", "XYZ")?
> >>>>>>>
> >>>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
> >>>>>>> will only be evaluated when the configuration is parsed.
> >>>>>>>
> >>>>>>> Oliver
> >>>>>>>
> >>>>>>>> Yes, it supports default values. Specify them as properties at
> >>>> the beginning of your configuration. Then when you specify something
> >> like
> >>>> ${sys:foo} if foo is not defined as a system property the default
> value
> >>>> will be used,
> >>>>>>>>
> >>>>>>>> Ralph
> >>>>>>>>
> >>>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
> >>>> <of...@vwd.com> wrote:
> >>>>>>>>>
> >>>>>>>>> Hi,
> >>>>>>>>>
> >>>>>>>>> I am considering to switch from slf4j/logback to log4j2;
> >>>>>>>>>
> >>>>>>>>> in slf4j/logback, I can specify a default value for a
> >>>> missing mdc entry
> >>>>>>>>> like this:
> >>>>>>>>>
> >>>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
> >>>> - %m%n</pattern>
> >>>>>>>>>
> >>>>>>>>> which would print "-" if mdc.get("FOO")
> >>>> is null (the ":-" separates
> >>>>>>>>> the key and the default value).
> >>>>>>>>>
> >>>>>>>>> Having a defined number of tokens/fields at the beginning
> >>>> of the log message
> >>>>>>>>> makes it easier to process it with awk/cut etc.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> Does log4j support default values? - I could not find any
> >>>> hint in the documentation
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> Regards,
> >>>>>>>>> Oliver
> >>>>>>>>>
> >>>>>>>>>
> >>>> ---------------------------------------------------------------------
> >>>>>>>>> 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
> >>>>>>>
> >>>>>>>
> >>>>>>> --
> >>>>>>> Oliver Flege
> >>>>>>> Senior Software Engineer | vwd group
> >>>>>>>
> >>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >>>>>>> oflege@vwd.com | www.vwd.com
> >>>>>>> ______________________________________________________________
> >>>>>>>
> >>>>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
> >>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >>>>>>> Vorstand: Dr. Ralf Kauther
> >>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >>>>
> >>>>>>> ____________________________________________________________
> >>>>>>>
> >>>>>>>
> >>>> ---------------------------------------------------------------------
> >>>>>>> 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
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Oliver Flege
> >>>>> Senior Software Engineer | vwd group
> >>>>>
> >>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >>>>> oflege@vwd.com | www.vwd.com
> >>>>> ______________________________________________________________
> >>>>>
> >>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
> >>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >>>>> Vorstand: Dr. Ralf Kauther
> >>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >>>>> ____________________________________________________________
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> 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
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >>
> >
> >
> > --
> > Jonathan Willis
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Jonathan Willis

Re: default value for missing key in mdc

Posted by Ralph Goers <ra...@dslextreme.com>.
Can you provide your lookup source? 


On Oct 9, 2013, at 1:22 PM, Jonathan Willis <qu...@gmail.com> wrote:

> http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2
> 
> 
> On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <ra...@dslextreme.com>wrote:
> 
>> Please remember that mine is just one opinion, but I am fine with that.  I
>> guess if no default value is provided this way then it can still fall back
>> to looking in the properties map.
>> 
>> Ralph
>> 
>> 
>> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
>> 
>>> Hi Ralph,
>>> 
>>> 
>>> I have something related to this improvement idea.
>>> I have thought it might be a bit more useful and flexible to allow
>> default value in the variable expression itself.
>>> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
>>> This generic feature has been included in StrSubstitutor of
>> commons-lang3 with the following issue:
>>> - https://issues.apache.org/jira/browse/LANG-893
>>> 
>>> I understand Oliver's patch should work more efficiently for map pattern
>> converters, but the goodness of the feature with LANG-893 is we can use it
>> more widely whenever used in look ups.
>>> 
>>> I know StrSubstitutor in log4j2 added more operations to deal with
>> LogEvent argument, so I can create a patch to include the feature of
>> LANG-893 if it is useful for others.
>>> Also, Oliver's patch won't conflict with this patch.
>>> 
>>> What do you think?
>>> 
>>> Kind regards,
>>> 
>>> Woonsan
>>> 
>>> 
>>>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <rg...@apache.org>
>> wrote:
>>>>> Patches are always welcome!
>>>> 
>>>> Ralph
>>>> 
>>>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
>>>> 
>>>>>> $${mdc:request_id} in a pattern should cause the request_id to be
>>>> evaluated on every event.
>>>>> 
>>>>> thanks a lot, $${ctx:request_id} seems to do the trick
>>>>> 
>>>>> however, the computation of the default value is quite complex as it
>> always
>>>> involves
>>>>> a variable substitution, and I cannot use conversion specifiers with
>> $$ as
>>>> I can with %X
>>>>> 
>>>>> Would you consider accepting a patch that adds support for slf4j-like
>>>> default values
>>>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
>>>>> 
>>>>> Regards,
>>>>> Oliver
>>>>> 
>>>>> 
>>>>> 
>>>>>> 
>>>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
>>>> wrote:
>>>>>>> 
>>>>>>> ok, this works for ${...} expressions in the configuration,
>>>> but I don't see how it would
>>>>>>> apply to pattern evaluation. To simplify and rephrase my original
>>>> question:
>>>>>>> 
>>>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>>>>>>> 
>>>>>>> is it possible to define a default value that will be printed
>>>>>>> if the thread never executed
>>>> ThreadContext.put("REQUEST_ID", "XYZ")?
>>>>>>> 
>>>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>>>>>>> will only be evaluated when the configuration is parsed.
>>>>>>> 
>>>>>>> Oliver
>>>>>>> 
>>>>>>>> Yes, it supports default values. Specify them as properties at
>>>> the beginning of your configuration. Then when you specify something
>> like
>>>> ${sys:foo} if foo is not defined as a system property the default value
>>>> will be used,
>>>>>>>> 
>>>>>>>> Ralph
>>>>>>>> 
>>>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
>>>> <of...@vwd.com> wrote:
>>>>>>>>> 
>>>>>>>>> Hi,
>>>>>>>>> 
>>>>>>>>> I am considering to switch from slf4j/logback to log4j2;
>>>>>>>>> 
>>>>>>>>> in slf4j/logback, I can specify a default value for a
>>>> missing mdc entry
>>>>>>>>> like this:
>>>>>>>>> 
>>>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
>>>> - %m%n</pattern>
>>>>>>>>> 
>>>>>>>>> which would print "-" if mdc.get("FOO")
>>>> is null (the ":-" separates
>>>>>>>>> the key and the default value).
>>>>>>>>> 
>>>>>>>>> Having a defined number of tokens/fields at the beginning
>>>> of the log message
>>>>>>>>> makes it easier to process it with awk/cut etc.
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Does log4j support default values? - I could not find any
>>>> hint in the documentation
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Regards,
>>>>>>>>> Oliver
>>>>>>>>> 
>>>>>>>>> 
>>>> ---------------------------------------------------------------------
>>>>>>>>> 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
>>>>>>> 
>>>>>>> 
>>>>>>> --
>>>>>>> Oliver Flege
>>>>>>> Senior Software Engineer | vwd group
>>>>>>> 
>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>>>> oflege@vwd.com | www.vwd.com
>>>>>>> ______________________________________________________________
>>>>>>> 
>>>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>>>>>> Vorstand: Dr. Ralf Kauther
>>>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>>> 
>>>>>>> ____________________________________________________________
>>>>>>> 
>>>>>>> 
>>>> ---------------------------------------------------------------------
>>>>>>> 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
>>>>> 
>>>>> 
>>>>> --
>>>>> Oliver Flege
>>>>> Senior Software Engineer | vwd group
>>>>> 
>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>> oflege@vwd.com | www.vwd.com
>>>>> ______________________________________________________________
>>>>> 
>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>>>> Vorstand: Dr. Ralf Kauther
>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>>>> ____________________________________________________________
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 
> 
> 
> -- 
> Jonathan Willis


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


Re: default value for missing key in mdc

Posted by Jonathan Willis <qu...@gmail.com>.
http://stackoverflow.com/questions/19277445/how-to-use-map-lookups-using-log4j2


On Wed, Oct 9, 2013 at 2:18 PM, Ralph Goers <ra...@dslextreme.com>wrote:

> Please remember that mine is just one opinion, but I am fine with that.  I
> guess if no default value is provided this way then it can still fall back
> to looking in the properties map.
>
> Ralph
>
>
> On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:
>
> > Hi Ralph,
> >
> >
> > I have something related to this improvement idea.
> > I have thought it might be a bit more useful and flexible to allow
> default value in the variable expression itself.
> > For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
> > This generic feature has been included in StrSubstitutor of
> commons-lang3 with the following issue:
> > - https://issues.apache.org/jira/browse/LANG-893
> >
> > I understand Oliver's patch should work more efficiently for map pattern
> converters, but the goodness of the feature with LANG-893 is we can use it
> more widely whenever used in look ups.
> >
> > I know StrSubstitutor in log4j2 added more operations to deal with
> LogEvent argument, so I can create a patch to include the feature of
> LANG-893 if it is useful for others.
> > Also, Oliver's patch won't conflict with this patch.
> >
> > What do you think?
> >
> > Kind regards,
> >
> > Woonsan
> >
> >
> >> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <rg...@apache.org>
> wrote:
> >>> Patches are always welcome!
> >>
> >> Ralph
> >>
> >> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
> >>
> >>>> $${mdc:request_id} in a pattern should cause the request_id to be
> >> evaluated on every event.
> >>>
> >>> thanks a lot, $${ctx:request_id} seems to do the trick
> >>>
> >>> however, the computation of the default value is quite complex as it
> always
> >> involves
> >>> a variable substitution, and I cannot use conversion specifiers with
> $$ as
> >> I can with %X
> >>>
> >>> Would you consider accepting a patch that adds support for slf4j-like
> >> default values
> >>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
> >>>
> >>> Regards,
> >>> Oliver
> >>>
> >>>
> >>>
> >>>>
> >>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com>
> >> wrote:
> >>>>>
> >>>>> ok, this works for ${...} expressions in the configuration,
> >> but I don't see how it would
> >>>>> apply to pattern evaluation. To simplify and rephrase my original
> >> question:
> >>>>>
> >>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
> >>>>>
> >>>>> is it possible to define a default value that will be printed
> >>>>> if the thread never executed
> >> ThreadContext.put("REQUEST_ID", "XYZ")?
> >>>>>
> >>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
> >>>>> will only be evaluated when the configuration is parsed.
> >>>>>
> >>>>> Oliver
> >>>>>
> >>>>>> Yes, it supports default values. Specify them as properties at
> >> the beginning of your configuration. Then when you specify something
> like
> >> ${sys:foo} if foo is not defined as a system property the default value
> >> will be used,
> >>>>>>
> >>>>>> Ralph
> >>>>>>
> >>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege
> >> <of...@vwd.com> wrote:
> >>>>>>>
> >>>>>>> Hi,
> >>>>>>>
> >>>>>>> I am considering to switch from slf4j/logback to log4j2;
> >>>>>>>
> >>>>>>> in slf4j/logback, I can specify a default value for a
> >> missing mdc entry
> >>>>>>> like this:
> >>>>>>>
> >>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0}
> >> - %m%n</pattern>
> >>>>>>>
> >>>>>>> which would print "-" if mdc.get("FOO")
> >> is null (the ":-" separates
> >>>>>>> the key and the default value).
> >>>>>>>
> >>>>>>> Having a defined number of tokens/fields at the beginning
> >> of the log message
> >>>>>>> makes it easier to process it with awk/cut etc.
> >>>>>>>
> >>>>>>>
> >>>>>>> Does log4j support default values? - I could not find any
> >> hint in the documentation
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> Regards,
> >>>>>>> Oliver
> >>>>>>>
> >>>>>>>
> >> ---------------------------------------------------------------------
> >>>>>>> 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
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Oliver Flege
> >>>>> Senior Software Engineer | vwd group
> >>>>>
> >>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >>>>> oflege@vwd.com | www.vwd.com
> >>>>> ______________________________________________________________
> >>>>>
> >>>>> vwd Vereinigte Wirtschaftsdienste AG
> >>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
> >>>>> Handelsregister: AG Frankfurt am Main HRB 81011
> >>>>> Vorstand: Dr. Ralf Kauther
> >>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >>
> >>>>> ____________________________________________________________
> >>>>>
> >>>>>
> >> ---------------------------------------------------------------------
> >>>>> 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
> >>>
> >>>
> >>> --
> >>> Oliver Flege
> >>> Senior Software Engineer | vwd group
> >>>
> >>> vwd Vereinigte Wirtschaftsdienste AG
> >>> Stiftsplatz 6/7 | 67655 Kaiserslautern
> >>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> >>> oflege@vwd.com | www.vwd.com
> >>> ______________________________________________________________
> >>>
> >>> vwd Vereinigte Wirtschaftsdienste AG
> >>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
> >>> Handelsregister: AG Frankfurt am Main HRB 81011
> >>> Vorstand: Dr. Ralf Kauther
> >>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> >>> ____________________________________________________________
> >>>
> >>> ---------------------------------------------------------------------
> >>> 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
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Jonathan Willis

Re: default value for missing key in mdc

Posted by Ralph Goers <ra...@dslextreme.com>.
Please remember that mine is just one opinion, but I am fine with that.  I guess if no default value is provided this way then it can still fall back to looking in the properties map.

Ralph


On Oct 9, 2013, at 12:53 PM, Woonsan Ko <wo...@yahoo.com> wrote:

> Hi Ralph,
> 
> 
> I have something related to this improvement idea.
> I have thought it might be a bit more useful and flexible to allow default value in the variable expression itself.
> For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
> This generic feature has been included in StrSubstitutor of commons-lang3 with the following issue:
> - https://issues.apache.org/jira/browse/LANG-893
> 
> I understand Oliver's patch should work more efficiently for map pattern converters, but the goodness of the feature with LANG-893 is we can use it more widely whenever used in look ups.
> 
> I know StrSubstitutor in log4j2 added more operations to deal with LogEvent argument, so I can create a patch to include the feature of LANG-893 if it is useful for others.
> Also, Oliver's patch won't conflict with this patch.
> 
> What do you think?
> 
> Kind regards,
> 
> Woonsan
> 
> 
>> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <rg...@apache.org> wrote:
>>> Patches are always welcome!
>> 
>> Ralph
>> 
>> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
>> 
>>>> $${mdc:request_id} in a pattern should cause the request_id to be 
>> evaluated on every event.
>>> 
>>> thanks a lot, $${ctx:request_id} seems to do the trick
>>> 
>>> however, the computation of the default value is quite complex as it always 
>> involves
>>> a variable substitution, and I cannot use conversion specifiers with $$ as 
>> I can with %X
>>> 
>>> Would you consider accepting a patch that adds support for slf4j-like 
>> default values
>>> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
>>> 
>>> Regards,
>>> Oliver
>>> 
>>> 
>>> 
>>>> 
>>>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com> 
>> wrote:
>>>>> 
>>>>> ok, this works for ${...} expressions in the configuration, 
>> but I don't see how it would
>>>>> apply to pattern evaluation. To simplify and rephrase my original 
>> question:
>>>>> 
>>>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>>>>> 
>>>>> is it possible to define a default value that will be printed
>>>>> if the thread never executed 
>> ThreadContext.put("REQUEST_ID", "XYZ")?
>>>>> 
>>>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>>>>> will only be evaluated when the configuration is parsed.
>>>>> 
>>>>> Oliver
>>>>> 
>>>>>> Yes, it supports default values. Specify them as properties at 
>> the beginning of your configuration. Then when you specify something like 
>> ${sys:foo} if foo is not defined as a system property the default value 
>> will be used,
>>>>>> 
>>>>>> Ralph
>>>>>> 
>>>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege 
>> <of...@vwd.com> wrote:
>>>>>>> 
>>>>>>> Hi,
>>>>>>> 
>>>>>>> I am considering to switch from slf4j/logback to log4j2;
>>>>>>> 
>>>>>>> in slf4j/logback, I can specify a default value for a 
>> missing mdc entry
>>>>>>> like this:
>>>>>>> 
>>>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0} 
>> - %m%n</pattern>
>>>>>>> 
>>>>>>> which would print "-" if mdc.get("FOO") 
>> is null (the ":-" separates
>>>>>>> the key and the default value).
>>>>>>> 
>>>>>>> Having a defined number of tokens/fields at the beginning 
>> of the log message
>>>>>>> makes it easier to process it with awk/cut etc.
>>>>>>> 
>>>>>>> 
>>>>>>> Does log4j support default values? - I could not find any 
>> hint in the documentation
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> Regards,
>>>>>>> Oliver
>>>>>>> 
>>>>>>> 
>> ---------------------------------------------------------------------
>>>>>>> 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
>>>>> 
>>>>> 
>>>>> -- 
>>>>> Oliver Flege
>>>>> Senior Software Engineer | vwd group
>>>>> 
>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>> oflege@vwd.com | www.vwd.com
>>>>> ______________________________________________________________
>>>>> 
>>>>> vwd Vereinigte Wirtschaftsdienste AG
>>>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>>>> Vorstand: Dr. Ralf Kauther
>>>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>> 
>>>>> ____________________________________________________________
>>>>> 
>>>>> 
>> ---------------------------------------------------------------------
>>>>> 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
>>> 
>>> 
>>> -- 
>>> Oliver Flege
>>> Senior Software Engineer | vwd group
>>> 
>>> vwd Vereinigte Wirtschaftsdienste AG
>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>> oflege@vwd.com | www.vwd.com
>>> ______________________________________________________________
>>> 
>>> vwd Vereinigte Wirtschaftsdienste AG
>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>> Vorstand: Dr. Ralf Kauther
>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>> ____________________________________________________________
>>> 
>>> ---------------------------------------------------------------------
>>> 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
> 


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


Re: default value for missing key in mdc

Posted by Woonsan Ko <wo...@yahoo.com>.
Hi Ralph,


I have something related to this improvement idea.
I have thought it might be a bit more useful and flexible to allow default value in the variable expression itself.
For example, ${var1:-defvalue1}, ${ctx:request_id:-defvalue2}, etc.
This generic feature has been included in StrSubstitutor of commons-lang3 with the following issue:
- https://issues.apache.org/jira/browse/LANG-893

I understand Oliver's patch should work more efficiently for map pattern converters, but the goodness of the feature with LANG-893 is we can use it more widely whenever used in look ups.

I know StrSubstitutor in log4j2 added more operations to deal with LogEvent argument, so I can create a patch to include the feature of LANG-893 if it is useful for others.
Also, Oliver's patch won't conflict with this patch.

What do you think?

Kind regards,

Woonsan


> On Tuesday, October 1, 2013 9:21 AM, Ralph Goers <rg...@apache.org> wrote:
> > Patches are always welcome!
> 
> Ralph
> 
> On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:
> 
>>>  $${mdc:request_id} in a pattern should cause the request_id to be 
> evaluated on every event.
>> 
>>  thanks a lot, $${ctx:request_id} seems to do the trick
>> 
>>  however, the computation of the default value is quite complex as it always 
> involves
>>  a variable substitution, and I cannot use conversion specifiers with $$ as 
> I can with %X
>> 
>>  Would you consider accepting a patch that adds support for slf4j-like 
> default values
>>  in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
>> 
>>  Regards,
>>  Oliver
>> 
>> 
>> 
>>> 
>>>>  On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com> 
> wrote:
>>>> 
>>>>  ok, this works for ${...} expressions in the configuration, 
> but I don't see how it would
>>>>  apply to pattern evaluation. To simplify and rephrase my original 
> question:
>>>> 
>>>>  Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>>>> 
>>>>  is it possible to define a default value that will be printed
>>>>  if the thread never executed 
> ThreadContext.put("REQUEST_ID", "XYZ")?
>>>> 
>>>>  I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>>>>  will only be evaluated when the configuration is parsed.
>>>> 
>>>>  Oliver
>>>> 
>>>>>  Yes, it supports default values. Specify them as properties at 
> the beginning of your configuration. Then when you specify something like 
> ${sys:foo} if foo is not defined as a system property the default value 
> will be used,
>>>>> 
>>>>>  Ralph
>>>>> 
>>>>>>  On Sep 30, 2013, at 3:30 AM, Oliver Flege 
> <of...@vwd.com> wrote:
>>>>>> 
>>>>>>  Hi,
>>>>>> 
>>>>>>  I am considering to switch from slf4j/logback to log4j2;
>>>>>> 
>>>>>>  in slf4j/logback, I can specify a default value for a 
> missing mdc entry
>>>>>>  like this:
>>>>>> 
>>>>>>  <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0} 
> - %m%n</pattern>
>>>>>> 
>>>>>>  which would print "-" if mdc.get("FOO") 
> is null (the ":-" separates
>>>>>>  the key and the default value).
>>>>>> 
>>>>>>  Having a defined number of tokens/fields at the beginning 
> of the log message
>>>>>>  makes it easier to process it with awk/cut etc.
>>>>>> 
>>>>>> 
>>>>>>  Does log4j support default values? - I could not find any 
> hint in the documentation
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>  Regards,
>>>>>>  Oliver
>>>>>> 
>>>>>> 
> ---------------------------------------------------------------------
>>>>>>  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
>>>> 
>>>> 
>>>>  -- 
>>>>  Oliver Flege
>>>>  Senior Software Engineer | vwd group
>>>> 
>>>>  vwd Vereinigte Wirtschaftsdienste AG
>>>>  Stiftsplatz 6/7 | 67655 Kaiserslautern
>>>>  Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>>>  oflege@vwd.com | www.vwd.com
>>>>  ______________________________________________________________
>>>> 
>>>>  vwd Vereinigte Wirtschaftsdienste AG
>>>>  Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>>>  Handelsregister: AG Frankfurt am Main HRB 81011
>>>>  Vorstand: Dr. Ralf Kauther
>>>>  Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> 
>>>>  ____________________________________________________________
>>>> 
>>>> 
> ---------------------------------------------------------------------
>>>>  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
>> 
>> 
>>  -- 
>>  Oliver Flege
>>  Senior Software Engineer | vwd group
>> 
>>  vwd Vereinigte Wirtschaftsdienste AG
>>  Stiftsplatz 6/7 | 67655 Kaiserslautern
>>  Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>  oflege@vwd.com | www.vwd.com
>>  ______________________________________________________________
>> 
>>  vwd Vereinigte Wirtschaftsdienste AG
>>  Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>  Handelsregister: AG Frankfurt am Main HRB 81011
>>  Vorstand: Dr. Ralf Kauther
>>  Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>  ____________________________________________________________
>> 
>>  ---------------------------------------------------------------------
>>  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: default value for missing key in mdc

Posted by Ralph Goers <rg...@apache.org>.
Patches are always welcome!

Ralph

On Oct 1, 2013, at 1:13 AM, Oliver Flege <of...@vwd.com> wrote:

>> $${mdc:request_id} in a pattern should cause the request_id to be evaluated on every event.
> 
> thanks a lot, $${ctx:request_id} seems to do the trick
> 
> however, the computation of the default value is quite complex as it always involves
> a variable substitution, and I cannot use conversion specifiers with $$ as I can with %X
> 
> Would you consider accepting a patch that adds support for slf4j-like default values
> in %X{key} and %K{key}, s.th. like %X{key:-defaultValue} ?
> 
> Regards,
> Oliver
> 
> 
> 
>> 
>>> On Sep 30, 2013, at 8:04 AM, Oliver Flege <of...@vwd.com> wrote:
>>> 
>>> ok, this works for ${...} expressions in the configuration, but I don't see how it would
>>> apply to pattern evaluation. To simplify and rephrase my original question:
>>> 
>>> Given a pattern layout with a pattern like:  %X{REQUEST_ID}
>>> 
>>> is it possible to define a default value that will be printed
>>> if the thread never executed ThreadContext.put("REQUEST_ID", "XYZ")?
>>> 
>>> I tried ${mdc:REQUEST_ID} + a Property REQUEST_ID, but that
>>> will only be evaluated when the configuration is parsed.
>>> 
>>> Oliver
>>> 
>>>> Yes, it supports default values. Specify them as properties at the beginning of your configuration. Then when you specify something like ${sys:foo} if foo is not defined as a system property the default value will be used,
>>>> 
>>>> Ralph
>>>> 
>>>>> On Sep 30, 2013, at 3:30 AM, Oliver Flege <of...@vwd.com> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> I am considering to switch from slf4j/logback to log4j2;
>>>>> 
>>>>> in slf4j/logback, I can specify a default value for a missing mdc entry
>>>>> like this:
>>>>> 
>>>>> <pattern>%d{HH:mm:ss} %X{FOO:--} %c{0} - %m%n</pattern>
>>>>> 
>>>>> which would print "-" if mdc.get("FOO") is null (the ":-" separates
>>>>> the key and the default value).
>>>>> 
>>>>> Having a defined number of tokens/fields at the beginning of the log message
>>>>> makes it easier to process it with awk/cut etc.
>>>>> 
>>>>> 
>>>>> Does log4j support default values? - I could not find any hint in the documentation
>>>>> 
>>>>> 
>>>>> 
>>>>> Regards,
>>>>> Oliver
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>> 
>>> 
>>> -- 
>>> Oliver Flege
>>> Senior Software Engineer | vwd group
>>> 
>>> vwd Vereinigte Wirtschaftsdienste AG
>>> Stiftsplatz 6/7 | 67655 Kaiserslautern
>>> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
>>> oflege@vwd.com | www.vwd.com
>>> ______________________________________________________________
>>> 
>>> vwd Vereinigte Wirtschaftsdienste AG
>>> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
>>> Handelsregister: AG Frankfurt am Main HRB 81011
>>> Vorstand: Dr. Ralf Kauther
>>> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
>>> ____________________________________________________________
>>> 
>>> ---------------------------------------------------------------------
>>> 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
> 
> 
> -- 
> Oliver Flege
> Senior Software Engineer | vwd group
> 
> vwd Vereinigte Wirtschaftsdienste AG
> Stiftsplatz 6/7 | 67655 Kaiserslautern
> Telefon: +49 631 3649-0 | Telefax: +49 631 3649-109
> oflege@vwd.com | www.vwd.com
> ______________________________________________________________
> 
> vwd Vereinigte Wirtschaftsdienste AG
> Sitz der Gesellschaft: Tilsiter Straße 1 | 60487 Frankfurt am Main
> Handelsregister: AG Frankfurt am Main HRB 81011
> Vorstand: Dr. Ralf Kauther
> Vorsitzender des Aufsichtsrates: Dr. Thorsten Dippel
> ____________________________________________________________
> 
> ---------------------------------------------------------------------
> 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