diff --git a/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/InMemoryCounterMetric.kt b/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/InMemoryCounterMetric.kt index dcd03c898..f032e95b1 100644 --- a/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/InMemoryCounterMetric.kt +++ b/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/InMemoryCounterMetric.kt @@ -1,15 +1,18 @@ package com.xebia.functional.xef.metrics import arrow.atomic.AtomicLong +import io.github.oshai.kotlinlogging.KLogger -class InMemoryCounterMetric : CounterMetric { +class InMemoryCounterMetric(val name: String, val logger: KLogger) : CounterMetric { private val count = AtomicLong(0) override fun increment(n: Long) { count.incrementAndGet() + logger.info { "Counter $name incremented to ${count.get()}" } } override fun decrement(n: Long) { count.decrementAndGet() + logger.info { "Counter $name decremented to ${count.get()}" } } } diff --git a/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/LogsMetric.kt b/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/LogsMetric.kt index 9304df7bc..ac18ca81f 100644 --- a/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/LogsMetric.kt +++ b/core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/LogsMetric.kt @@ -115,14 +115,14 @@ class LogsMetric(private val level: Level = Level.INFO) : Metric { override suspend fun createCounter(name: String): CounterMetric { logger.at(level) { message = "${writeIndent(numberOfBlocks.get())}> Created counter: $name" } - val counter = InMemoryCounterMetric() + val counter = InMemoryCounterMetric(name, logger) countersMap[name] = counter return counter } override suspend fun getCounter(name: String): CounterMetric { logger.at(level) { message = "${writeIndent(numberOfBlocks.get())}> Get counter: $name" } - return countersMap[name] ?: InMemoryCounterMetric() + return countersMap[name] ?: InMemoryCounterMetric(name, logger) } private fun writeIndent(times: Int = 1) = (1..indentSize * times).fold("") { a, _ -> "$a " }