Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2 double dollar $$ sign meaning in configuration

Tags:

java

log4j2

I am reading the configuration part of Log4j2. http://logging.apache.org/log4j/2.x/manual/configuration.html

<Appenders>
    <Console name="STDOUT">
      <PatternLayout pattern="%m%n"/>
    </Console>
    <List name="List">
      <ThresholdFilter level="debug"/>
    </List>
    <Routing name="Routing">
      <Routes pattern="$${sd:type}">
        <Route>
          <RollingFile name="Rolling-${sd:type}" fileName="${filename}"
                       filePattern="target/rolling1/test1-${sd:type}.%i.log.gz">
            <PatternLayout>
              <pattern>%d %p %c{1.} [%t] %m%n</pattern>
            </PatternLayout>
            <SizeBasedTriggeringPolicy size="500" />
          </RollingFile>
        </Route>
        <Route ref="STDOUT" key="Audit"/>
        <Route ref="List" key="Service"/>
      </Routes>
    </Routing>
  </Appenders>

What is the meaning of double $$ sign? e.g. $${sd:type}?

like image 997
user3544765 Avatar asked Sep 08 '16 14:09

user3544765


People also ask

What does $$ mean in log4j2?

It seems that $ is used as an escape character. As stated in Log4J documentation, Log4j configuration file parser uses Apache Commons Lang's StrSubstitutor , and this documentation for StrSubstitutor says: The other possibility is to use the escape character, by default '$'.

What is configuration status in log4j2?

Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.

What is pattern layout in log4j2?

Layout class and overrides the format() method to structure the logging information according to a supplied pattern. PatternLayout is also a simple Layout object that provides the following-Bean Property which can be set using the configuration file: Sr.No.


1 Answers

It seems that $ is used as an escape character. As stated in Log4J documentation, Log4j configuration file parser uses Apache Commons Lang's StrSubstitutor, and this documentation for StrSubstitutor says:

The other possibility is to use the escape character, by default '$'. If this character is placed before a variable reference, this reference is ignored and won't be replaced. For example:

The variable $${${name}} must be used.

I guess they want to set the value to "${sd:type}" so that this variable can be evaluated later at run-time. There is a good example/explanation here: http://logging.apache.org/log4j/2.x/manual/lookups.html#ContextMapLookup

like image 127
xav Avatar answered Oct 29 '22 08:10

xav