[
https://issues.apache.org/jira/browse/LOG4J2-2062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16193190#comment-16193190
]
ASF GitHub Bot commented on LOG4J2-2062:
----------------------------------------
Github user mikaelstaldal commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/112#discussion_r142994778
--- Diff:
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManager.java
---
@@ -47,18 +47,24 @@
private final int timeoutMillis;
private final String topic;
+ private final byte[] key;
private final boolean syncSend;
- public KafkaManager(final LoggerContext loggerContext, final String
name, final String topic, final boolean syncSend, final Property[] properties) {
+ public KafkaManager(final LoggerContext loggerContext, final String
name, final String topic, final boolean syncSend,
+ final Property[] properties, final String key) {
super(loggerContext, name);
this.topic = Objects.requireNonNull(topic, "topic");
this.syncSend = syncSend;
config.setProperty("key.serializer",
"org.apache.kafka.common.serialization.ByteArraySerializer");
config.setProperty("value.serializer",
"org.apache.kafka.common.serialization.ByteArraySerializer");
config.setProperty("batch.size", "0");
for (final Property property : properties) {
+
config.setProperty(property.getName(), property.getValue());
}
+
+ this.key = (key != null ) ? key.getBytes() : null ;
--- End diff --
`key.getBytes()` will use some platform default charset. It's not good to
rely on that, better to specify charset explicitly.
> Add possibility of sending the key of a message to Kafka using KafkaAppender
> ----------------------------------------------------------------------------
>
> Key: LOG4J2-2062
> URL: https://issues.apache.org/jira/browse/LOG4J2-2062
> Project: Log4j 2
> Issue Type: Improvement
> Components: Appenders
> Affects Versions: 2.9.0, 2.9.1
> Reporter: Jorge Sanchez
> Assignee: Mikael Ståldal
> Priority: Minor
>
> When using the KafkaAppender the KafkaManager only sends the value of a
> message to a Kafka topic.
> It could be useful to be able to assign a value to the key of that message
> via configuration instead of having it null.
> Check
> https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManager.java#L99
> Updated with link to the PR: https://github.com/apache/logging-log4j2/pull/112
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)