Skip to content

Commit afed0be

Browse files
committed
logger small refactor
1 parent 0cd3ee1 commit afed0be

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

compiler-plugin/src/main/kotlin/io/github/stslex/compiler_plugin/DistinctChangeCache.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package io.github.stslex.compiler_plugin
22

33
import io.github.stslex.compiler_plugin.model.DistinctChangeConfig
44
import io.github.stslex.compiler_plugin.utils.RuntimeLogger
5+
import org.jetbrains.kotlin.utils.addToStdlib.runIf
56

67
internal class DistinctChangeCache(
78
private val config: DistinctChangeConfig
89
) {
910

1011
private val cache = mutableMapOf<String, Pair<List<Any?>, Any?>>()
11-
private val logger = RuntimeLogger.tag("DistinctChangeLogger")
12+
private val logger = runIf(config.logging) { RuntimeLogger.tag("DistinctChangeLogger") }
1213

1314
@Suppress("UNCHECKED_CAST")
1415
internal operator fun <R> invoke(
@@ -18,18 +19,15 @@ internal class DistinctChangeCache(
1819
): R {
1920
val entry = cache[key]
2021

21-
// log enter to invoke processing
22-
if (config.logging) {
23-
logger.i("name: ${config.name} key: $key, config:$config, entry: $entry, args: $args")
24-
}
22+
logger?.i("name: ${config.name} key: $key, config:$config, entry: $entry, args: $args")
2523

2624
config.action(
2725
name = config.name,
2826
isProcess = entry != null && entry.first == args
2927
)
3028

3129
if (entry != null && entry.first == args) {
32-
if (config.logging) logger.i("${config.name} with key $key not change")
30+
logger?.i("${config.name} with key $key not change")
3331
return entry.second as R
3432
}
3533

0 commit comments

Comments
 (0)