diff --git a/CHANGELOG.md b/CHANGELOG.md index b22475c..219391e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.0.2 + +* New logger `TagLogger` and now extension `Any#logger` will use it to decrease objects allocations +* Now it is possible to create `KSLog` using any iterable +* Now it is possible to create `KSLog` using vararg log levels + ## 0.0.1 * Project has been inited diff --git a/gradle.properties b/gradle.properties index 31a7499..c615e26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,5 +9,5 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.1 -android_code_version=1 +version=0.0.2 +android_code_version=2 diff --git a/src/commonMain/kotlin/AutoLoggers.kt b/src/commonMain/kotlin/AutoLoggers.kt index 042013e..e1803e7 100644 --- a/src/commonMain/kotlin/AutoLoggers.kt +++ b/src/commonMain/kotlin/AutoLoggers.kt @@ -2,7 +2,5 @@ package dev.inmo.kslog.common val Any.logTag get() = this::class.simpleName ?: error("Unable to retrieve log tag") -val Any.logger - get() = CallbackKSLog { l, t, m, e -> - KSLog.default.performLog(l, t ?: logTag, m, e) - } +val Any.logger: KSLog + get() = TagLogger(logTag) diff --git a/src/commonMain/kotlin/KSLog.kt b/src/commonMain/kotlin/KSLog.kt index 495b152..1a9a902 100644 --- a/src/commonMain/kotlin/KSLog.kt +++ b/src/commonMain/kotlin/KSLog.kt @@ -44,11 +44,21 @@ expect fun KSLog( fun KSLog( defaultTag: String, - levels: Set -): KSLog = KSLog (defaultTag) { l, _, _, _ -> - l in levels + levels: Iterable +): KSLog { + val levels = levels.toSet() + return KSLog (defaultTag) { l, _, _, _ -> + l in levels + } } +inline fun KSLog( + defaultTag: String, + firstLevel: LogLevel, + secondLevel: LogLevel, + vararg otherLevels: LogLevel +): KSLog = KSLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels)) + fun KSLog( defaultTag: String, minLoggingLevel: LogLevel = LogLevel.VERBOSE diff --git a/src/commonMain/kotlin/TagLogger.kt b/src/commonMain/kotlin/TagLogger.kt new file mode 100644 index 0000000..7fe1286 --- /dev/null +++ b/src/commonMain/kotlin/TagLogger.kt @@ -0,0 +1,10 @@ +package dev.inmo.kslog.common + +import kotlin.jvm.JvmInline + +@JvmInline +value class TagLogger(val tag: String) : KSLog { + override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) { + KSLog.performLog(level, tag ?: tag, message, throwable) + } +}