Log4j2 Howto在自定义字段中从MapMessage查找值

时间:2018-12-17 13:37:57

标签: java log4j2

Map lookup docs说,地图查找可用于从LogEvents中的MapMessages检索值。

JSONLayout docs说,查找可用于检索值。

我正在尝试将这2件组合在一起:

<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>">
<style type="text/css">  
    @font-face{
        font-family: 'Muli';
        src:'<?php echo get_template_directory(); ?>/dompdf/lib/fonts/Muli.ttf';
    }      
    h1,h2,h3,h4,h5 {
        font-family: 'Muli', sans-serif;
    }
    h1.title{ color: #6c9bcb !important}
    p, a{font-size: 16px;font-family: 'Muli', sans-serif;}
    footer a{color: #333;}     
</style>

我使用以下配置:

logger.info(new MapMessage<>(Map.of("key1", "value1")));

但该值未插值:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <JsonLayout>
            <KeyValuePair key="additionalField1" value="constant value"/>
            <KeyValuePair key="additionalField2" value="${map:key1}"/>
        </JsonLayout>
    </Console>
</Appenders>
<Loggers>
    <Root level="debug">
        <AppenderRef ref="Console"/>
    </Root>
</Loggers>
</Configuration>

我想念什么吗?

1 个答案:

答案 0 :(得分:0)

我认为这是log4j2的错误,并在Jira提出了要求: https://issues.apache.org/jira/projects/LOG4J2/issues/LOG4J2-2522