MINOR: Only include transactional id in LogContext if it's set
Author: Ismael Juma
Reviewers: Apurva Mehta Jason Gustafson
Closes from ijuma/transactional-id-should-be-optional-in-log-context
@@ -316,7 +316,11 @@ public class KafkaProducer<K, V> implements Producer<K, V> {
String transactionalId = userProvidedConfigs.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG) ?
(String) userProvidedConfigs.get(ProducerConfig.TRANSACTIONAL_ID_CONFIG) : null;
- LogContext logContext = new LogContext(String.format("[Producer clientId=%s, transactionalId=%s] ", clientId, transactionalId));
+ LogContext logContext;
+ if (transactionalId == null)
+ logContext = new LogContext(String.format("[Producer clientId=%s] ", clientId));
+ else
+ logContext = new LogContext(String.format("[Producer clientId=%s, transactionalId=%s] ", clientId, transactionalId));
log = logContext.logger(KafkaProducer.class);
log.trace("Starting the Kafka producer");
