在KafkaAppender中设置键值对。

huangapple go评论82阅读模式
英文:

Set KeyValuePair in KafkaAppender

问题

在这里,我想设置键值对。所有其他功能都正常工作。

我想使用log4j2.properties文件。

appender.kafka=org.apache.kafka
appender.kafka.type=kafka
appender.kafka.name=kafkaAppender
appender.kafka.topic=NewTopic
appender.kafka.property.type=Property
appender.kafka.property.name=bootstrap.servers
appender.kafka.property.value=host:ip
appender.kafka.property2.type=Property
appender.kafka.property2.name=group.id
appender.kafka.property2.value=new_group_id
appender.kafka.layout.type=JSONLayout
appender.kafka.property3.type=KeyValuePair  <--- 不起作用
appender.kafka.property3.name=originalGuid  <--- 不起作用
appender.kafka.property3.value=value       <--- 不起作用

当我尝试这种方式时,它可以工作。但我不想使用log4j2.xml文件。

<Kafka name="kafkaLogAppender" topic="${kafka.topic.logs}">
    <JsonLayout>
        <KeyValuePair key="guid" value="$${ctx:guid:-}"/>
        <KeyValuePair key="originalGuid" value="$${ctx:originalGuid:-}"/>
        <KeyValuePair key="gateGroupCode" value="$${ctx:gateGroupCode:-}"/>
        <KeyValuePair key="037Message" value="$${ctx:037Message:-}"/>
        <KeyValuePair key="titleMessage" value="$${ctx:titleMessage:-}"/>
    </JsonLayout>
    <Property name="bootstrap.servers">${bootstrap.servers}</Property>
    <Property name="group.id">${group.id}</Property>
    <MarkerFilter marker="${audit.logmarker}" onMatch="DENY" onMismatch="ACCEPT"/>
</Kafka>

但是当我尝试在properties文件中时,无法设置键值对。

英文:

Here i want to set key value pair. all other features are working.

i want to use log4j2.properties file.

appender.kafka=org.apache.kafka
appender.kafka.type= kafka
appender.kafka.name= kafkaAppender
appender.kafka.topic= NewTopic
appender.kafka.property.type=Property
appender.kafka.property.name=bootstrap.servers
appender.kafka.property.value=host:ip
appender.kafka.property2.type=Property
appender.kafka.property2.name=group.id
appender.kafka.property2.value=new_group_id
appender.kafka.layout.type = JSONLayout
appender.kafka.property3.type=KeyValuePair  &lt;--- not work
appender.kafka.property3.name=originalGuid  &lt;--- not work
appender.kafka.property3.value= value       &lt;--- not work

it works when i try it this way. but i dont want to use log4j2.xml file.

       &lt;Kafka name=&quot;kafkaLogAppender&quot; topic=&quot;${kafka.topic.logs}&quot;&gt;
            &lt;JsonLayout&gt;
                &lt;KeyValuePair key=&quot;guid&quot; value=&quot;$${ctx:guid:-}&quot;/&gt;
                &lt;KeyValuePair key=&quot;originalGuid&quot; value=&quot;$${ctx:originalGuid:-}&quot;/&gt;
                &lt;KeyValuePair key=&quot;gateGroupCode&quot; value=&quot;$${ctx:gateGroupCode:-}&quot;/&gt;
                &lt;KeyValuePair key=&quot;037Message&quot; value=&quot;$${ctx:037Message:-}&quot;/&gt;
                &lt;KeyValuePair key=&quot;titleMessage&quot; value=&quot;$${ctx:titleMessage:-}&quot;/&gt;
            &lt;/JsonLayout&gt;
            &lt;Property name=&quot;bootstrap.servers&quot;&gt;${bootstrap.servers}&lt;/Property&gt;
            &lt;Property name=&quot;group.id&quot;&gt;${group.id}&lt;/Property&gt;
            &lt;MarkerFilter marker=&quot;${audit.logmarker}&quot; onMatch=&quot;DENY&quot; onMismatch=&quot;ACCEPT&quot;/&gt;
        &lt;/Kafka&gt; 

but when I tried in properties file, I couldn't set the keyvaluepair.

答案1

得分: 1

由于KeyValuePairJsonLayout的子组件,其前缀需要以appender.kafka.layout开头,例如:

appender.kafka.layout.k1.type=KeyValuePair
appender.kafka.layout.k1.name=originalGuid
appender.kafka.layout.k1.value=value
英文:

Since KeyValuePair is a subcomponent of JsonLayout, its prefix needs to start with appender.kafka.layout, e.g.:

appender.kafka.layout.k1.type=KeyValuePair
appender.kafka.layout.k1.name=originalGuid
appender.kafka.layout.k1.value=value

huangapple
  • 本文由 发表于 2023年7月3日 20:18:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76604678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定