Patches are always welcome! Ralph
On Oct 1, 2013, at 1:13 AM, Oliver Flege <ofl...@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 <ofl...@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 <ofl...@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-unsubscr...@logging.apache.org >>>>> For additional commands, e-mail: log4j-user-h...@logging.apache.org >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org >>>> For additional commands, e-mail: log4j-user-h...@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 >>> ofl...@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-unsubscr...@logging.apache.org >>> For additional commands, e-mail: log4j-user-h...@logging.apache.org >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org >> For additional commands, e-mail: log4j-user-h...@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 > ofl...@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-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org