Log4j2 - 财产替换是否被窃听?

时间:2018-03-29 15:28:21

标签: java logging log4j2

Log4j2

xml配置文件中的<Properties>元素仅在<Configuration>下声明为第一个元素时才有效吗?

测试案例1:

TestLog4jBug.java

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class TestLog4jBug {

    public static void main(String[] args) {
      Logger logger = LogManager.getRootLogger();
      logger.trace("message");
    }

}

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">

<Properties>
    <Property name="defaultPatternLayout">[%d{yyyy-MM-dd HH:mm:ss.SSS}] [Thread: %t] [%level] %logger{36}.%M - %msg%n</Property>
</Properties>

<CustomLevels>
    <CustomLevel name="OUTPUT" intLevel="700" />
</CustomLevels>

<Appenders>
    <Console name="console-log">
        <PatternLayout pattern="${defaultPatternLayout}" />
    </Console>
</Appenders>

<Loggers>
    <Root level="all">
        <AppenderRef ref="console-log"/>
    </Root>
</Loggers>

控制台输出

[2018-03-29 17:14:49.490] [Thread: main] [TRACE] .main - message

测试案例2:

TestLog4jBug.java与上述相同

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">

<CustomLevels>
    <CustomLevel name="OUTPUT" intLevel="700" />
</CustomLevels>

<Properties>
    <Property name="defaultPatternLayout">[%d{yyyy-MM-dd HH:mm:ss.SSS}] [Thread: %t] [%level] %logger{36}.%M - %msg%n</Property>
</Properties>

<Appenders>
    <Console name="console-log">
        <PatternLayout pattern="${defaultPatternLayout}" />
    </Console>
</Appenders>

<Loggers>
    <Root level="all">
        <AppenderRef ref="console-log"/>
    </Root>
</Loggers>

控制台输出

${defaultPatternLayout}

0 个答案:

没有答案