New to Scala, trying to compute and log latency for my kafka records using log4j, but running into errors. Tried to look at some SO articles but I think I missing some Scala concept here. Any help is appreciated.
Solution1: Does not give an error.
val currentTimeInMillis = Instant.now.toEpochMilli
val latency = Math.max(0, currentTimeInMillis - record.timestamp())
logger.info("record latency: {}", latency)
logger.info("record KafkaPartition: {}, record Offset: {}", record.kafkaPartition(), record.kafkaOffset())
Solution2: This gives error:
val currentTimeInMillis = Instant.now.toEpochMilli
val latency = Math.max(0, currentTimeInMillis - record.timestamp())
logger.info("record latency: {}, record KafkaPartition: {}, record Offset: {}", latency, record.kafkaPartition(), record.kafkaOffset())
Getting below error for Solution2:
error: overloaded method value info with alternatives
[ERROR] (x$1: org.slf4j.Marker,x$2: String,x$3: Object*)Unit <and>
[ERROR] (x$1: org.slf4j.Marker,x$2: String,x$3: Any,x$4: Any)Unit <and>
[ERROR] (x$1: String,x$2: Object*)Unit
[ERROR] cannot be applied to (String, Long, Integer, Long)
[ERROR] logger.info("record latency: {}, record KafkaPartition: {}, record Offset: {}", latency, record.kafkaPartition(), record.kafkaOffset())
[ERROR] ^
[ERROR] one error found