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 Behrang Saeedzadeh <be...@gmail.com> on 2018/01/04 00:40:32 UTC

Do we need two leading $ signs for lookups inside XML elements and one $ inside XML attributes?

From the docs, $$ inside the <pattern> element:


   1. <File name="Application" fileName="application.log">
   2. <PatternLayout>
   3. <pattern>%d %p %c{1.} [%t] $${env:USER} %m%n</pattern>
   4. </PatternLayout>
   5. </File>


Also from the docs, $ inside the header attribute:


   1. <File name="Application" fileName="application.log">
   2. <PatternLayout header="${java:runtime} - ${java:vm} - ${java:os}">
   3. <Pattern>%d %m%n</Pattern>
   4. </PatternLayout>
   5. </File>


I just read the docs on property substitution and how StrLookup treat
variables with multiple leading '$' characters, but it is not obvious to me
why in the two examples above, in one example two leading $ signs are used,
and in the other only one $ is used.

Best regards,
Behrang Saeedzadeh

Re: Do we need two leading $ signs for lookups inside XML elements and one $ inside XML attributes?

Posted by Behrang Saeedzadeh <be...@gmail.com>.
Thanks for the clarification Ralph.

Best regards,
Behrang Saeedzadeh

On 4 January 2018 at 13:27, Ralph Goers <ra...@dslextreme.com> wrote:

> When the configuration is read all variables are resolved, so every
> variable with a single $ will be replaced with its value. When a variable
> needs to be resolved at run time you must use 2 $ characters. The first
> will be stripped off leaving the variable reference. That property will
> then be evaluated at the appropriate time.
>
> In the configuration below $${env:USER} would be evaluated for each log
> event. However, since “env” means it is an environment variable it is
> unlikely this value will change at runtime so it could have been specified
> with a single $. If it had been $${mdc:USER} then the USER variable from
> the thread context at the time the log event is processed would be
> substituted.
>
> Ralph
>
> > On Jan 3, 2018, at 5:40 PM, Behrang Saeedzadeh <be...@gmail.com>
> wrote:
> >
> > From the docs, $$ inside the <pattern> element:
> >
> >
> >   1. <File name="Application" fileName="application.log">
> >   2. <PatternLayout>
> >   3. <pattern>%d %p %c{1.} [%t] $${env:USER} %m%n</pattern>
> >   4. </PatternLayout>
> >   5. </File>
> >
> >
> > Also from the docs, $ inside the header attribute:
> >
> >
> >   1. <File name="Application" fileName="application.log">
> >   2. <PatternLayout header="${java:runtime} - ${java:vm} - ${java:os}">
> >   3. <Pattern>%d %m%n</Pattern>
> >   4. </PatternLayout>
> >   5. </File>
> >
> >
> > I just read the docs on property substitution and how StrLookup treat
> > variables with multiple leading '$' characters, but it is not obvious to
> me
> > why in the two examples above, in one example two leading $ signs are
> used,
> > and in the other only one $ is used.
> >
> > Best regards,
> > Behrang Saeedzadeh
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Do we need two leading $ signs for lookups inside XML elements and one $ inside XML attributes?

Posted by Ralph Goers <ra...@dslextreme.com>.
When the configuration is read all variables are resolved, so every variable with a single $ will be replaced with its value. When a variable needs to be resolved at run time you must use 2 $ characters. The first will be stripped off leaving the variable reference. That property will then be evaluated at the appropriate time.

In the configuration below $${env:USER} would be evaluated for each log event. However, since “env” means it is an environment variable it is unlikely this value will change at runtime so it could have been specified with a single $. If it had been $${mdc:USER} then the USER variable from the thread context at the time the log event is processed would be substituted.

Ralph

> On Jan 3, 2018, at 5:40 PM, Behrang Saeedzadeh <be...@gmail.com> wrote:
> 
> From the docs, $$ inside the <pattern> element:
> 
> 
>   1. <File name="Application" fileName="application.log">
>   2. <PatternLayout>
>   3. <pattern>%d %p %c{1.} [%t] $${env:USER} %m%n</pattern>
>   4. </PatternLayout>
>   5. </File>
> 
> 
> Also from the docs, $ inside the header attribute:
> 
> 
>   1. <File name="Application" fileName="application.log">
>   2. <PatternLayout header="${java:runtime} - ${java:vm} - ${java:os}">
>   3. <Pattern>%d %m%n</Pattern>
>   4. </PatternLayout>
>   5. </File>
> 
> 
> I just read the docs on property substitution and how StrLookup treat
> variables with multiple leading '$' characters, but it is not obvious to me
> why in the two examples above, in one example two leading $ signs are used,
> and in the other only one $ is used.
> 
> Best regards,
> Behrang Saeedzadeh



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