英文:
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 <--- not work
appender.kafka.property3.name=originalGuid <--- not work
appender.kafka.property3.value= value <--- not work
it works when i try it this way. but i dont want to use log4j2.xml file.
<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>
but when I tried in properties file, I couldn't set the keyvaluepair.
答案1
得分: 1
由于KeyValuePair
是JsonLayout
的子组件,其前缀需要以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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论