Merge pull request #4 from InsanusMokrassar/0.0.2

0.0.2
This commit is contained in:
InsanusMokrassar 2022-06-08 16:11:40 +06:00 committed by GitHub
commit de56994cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -44,11 +44,21 @@ expect fun KSLog(
fun KSLog(
defaultTag: String,
levels: Set<LogLevel>
): KSLog = KSLog (defaultTag) { l, _, _, _ ->
l in levels
levels: Iterable<LogLevel>
): 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

View File

@ -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)
}
}