I am using log4j2 with a JSON properties file I am naming log4j2.json and attempting to add a kafka appender. There are plenty of examples using the older formats or xml, but struggling to get the correct format in JSON. This is most likely a silly question, but I have been struggling to get this to work and can find no examples anywhere. I am tempted to abandoned configuring log4j2 in json and moving to XML, but I feel this should be rather simple.
Here is a sample kafka appender defined in XML.
'<Appenders>
<Kafka name="Kafka" topic="devglan-test">
<PatternLayout pattern="%date %message"/>
<Property name="bootstrap.servers">localhost:9092</Property>
</Kafka>
<Async name="Async">
<AppenderRef ref="Kafka"/>
</Async>
</Appenders>
How does the
'localhost:9092
entry map to JSON.
I have tried a number of styles such as the following: '"Kafka": { "name":"Kafka", "topic":"FEEDPROCESSING_Dev", "PatternLayout": { "pattern": "%date %message" }, "bootstrap.servers": [{"name":"localhost:9092"}]} }
That did not work. I also tried..
'"Kafka": {
"name":"Kafka",
"topic":"FEEDPROCESSING_SYNC_Dev",
"PatternLayout": {
"pattern": "%date %message"
},
"Property": {"bootstrap.servers":"localhost:9092"}}
}
I am getting errors like: Property contains an invalid element or attribute "bootstrap.servers"
THis configuration gives me the error "Unable to locate plugin type for bootstrap.servers":
'"Property": {"bootstrap.servers":[{"name":"localhost:9092"}]}}},
I know I have the correct maven dependencies..
What is the correct way to configure a Kafka appender, particular the bootstrap server property,using JSON and log4j2?