diff --git a/napier/src/androidMain/kotlin/io/github/aakira/napier/DebugAntilog.kt b/napier/src/androidMain/kotlin/io/github/aakira/napier/DebugAntilog.kt index e4d5f7e..975de67 100644 --- a/napier/src/androidMain/kotlin/io/github/aakira/napier/DebugAntilog.kt +++ b/napier/src/androidMain/kotlin/io/github/aakira/napier/DebugAntilog.kt @@ -7,7 +7,10 @@ import java.io.StringWriter import java.util.regex.Pattern import kotlin.math.min -actual class DebugAntilog actual constructor(private val defaultTag: String) : Antilog() { +actual class DebugAntilog actual constructor( + private val defaultTag: String, + private val logLevelChecker: (LogLevel, String?) -> Boolean +) : Antilog() { companion object { private const val MAX_LOG_LENGTH = 4000 @@ -17,6 +20,8 @@ actual class DebugAntilog actual constructor(private val defaultTag: String) : A private val anonymousClass = Pattern.compile("(\\$\\d+)+$") + override fun isEnable(priority: LogLevel, tag: String?): Boolean = logLevelChecker(priority, tag) + override fun performLog( priority: LogLevel, tag: String?, diff --git a/napier/src/commonMain/kotlin/io/github/aakira/napier/DebugAntilog.kt b/napier/src/commonMain/kotlin/io/github/aakira/napier/DebugAntilog.kt index 7318127..3ff282e 100644 --- a/napier/src/commonMain/kotlin/io/github/aakira/napier/DebugAntilog.kt +++ b/napier/src/commonMain/kotlin/io/github/aakira/napier/DebugAntilog.kt @@ -1,3 +1,30 @@ package io.github.aakira.napier -expect class DebugAntilog(defaultTag: String = "app") : Antilog \ No newline at end of file +import kotlin.js.JsName +import kotlin.jvm.JvmName + +expect class DebugAntilog( + defaultTag: String = "app", + logLevelChecker: (LogLevel, String?) -> Boolean +) : Antilog + + +@JvmName("DebugAntilogFromLogLevels") +@JsName("DebugAntilogFromLogLevels") +fun DebugAntilog( + defaultTag: String = "app", + enabledLevels: Array = LogLevel.values() +) = DebugAntilog(defaultTag) { level, _ -> level in enabledLevels } + +fun DebugAntilog( + defaultTag: String = "app", + enabledLevels: Iterable +) = DebugAntilog(defaultTag, enabledLevels.toList().toTypedArray()) + +fun DebugAntilog( + defaultTag: String = "app", + vararg enabledLevels: LogLevel +): DebugAntilog { + @Suppress("UNCHECKED_CAST") + return DebugAntilog(defaultTag, enabledLevels as Array) +} diff --git a/napier/src/darwinMain/kotlin/io/github/aakira/napier/DebugAntilog.kt b/napier/src/darwinMain/kotlin/io/github/aakira/napier/DebugAntilog.kt index 45174ad..439ab6d 100644 --- a/napier/src/darwinMain/kotlin/io/github/aakira/napier/DebugAntilog.kt +++ b/napier/src/darwinMain/kotlin/io/github/aakira/napier/DebugAntilog.kt @@ -9,8 +9,16 @@ private const val CALL_STACK_INDEX = 8 actual class DebugAntilog( private val defaultTag: String = "app", private val coroutinesSuffix: Boolean = true, + private val logLevelChecker: (LogLevel, String?) -> Boolean = { _, _ -> true }, ) : Antilog() { - actual constructor(defaultTag: String) : this(defaultTag, coroutinesSuffix = true) + actual constructor( + defaultTag: String, + logLevelChecker: (LogLevel, String?) -> Boolean + ) : this( + defaultTag, + coroutinesSuffix = true, + logLevelChecker = logLevelChecker + ) var crashAssert = false @@ -27,6 +35,8 @@ actual class DebugAntilog( LogLevel.ASSERT to "💞 ASSERT" ) + override fun isEnable(priority: LogLevel, tag: String?): Boolean = logLevelChecker(priority, tag) + override fun performLog( priority: LogLevel, tag: String?, diff --git a/napier/src/jsMain/kotlin/io/github/aakira/napier/DebugAntilog.kt b/napier/src/jsMain/kotlin/io/github/aakira/napier/DebugAntilog.kt index 6eb1744..6502583 100644 --- a/napier/src/jsMain/kotlin/io/github/aakira/napier/DebugAntilog.kt +++ b/napier/src/jsMain/kotlin/io/github/aakira/napier/DebugAntilog.kt @@ -1,6 +1,11 @@ package io.github.aakira.napier -actual class DebugAntilog actual constructor(private val defaultTag: String) : Antilog() { +actual class DebugAntilog actual constructor( + private val defaultTag: String, + private val logLevelChecker: (LogLevel, String?) -> Boolean +) : Antilog() { + + override fun isEnable(priority: LogLevel, tag: String?): Boolean = logLevelChecker(priority, tag) override fun performLog( priority: LogLevel, diff --git a/napier/src/jvmMain/kotlin/io/github/aakira/napier/DebugAntilog.kt b/napier/src/jvmMain/kotlin/io/github/aakira/napier/DebugAntilog.kt index 9232023..88d0118 100644 --- a/napier/src/jvmMain/kotlin/io/github/aakira/napier/DebugAntilog.kt +++ b/napier/src/jvmMain/kotlin/io/github/aakira/napier/DebugAntilog.kt @@ -7,9 +7,17 @@ import java.util.regex.Pattern actual class DebugAntilog( private val defaultTag: String = "app", - private val handler: List = listOf() + private val handler: List = listOf(), + private val logLevelChecker: (LogLevel, String?) -> Boolean = { _, _ -> true } ) : Antilog() { - actual constructor(defaultTag: String) : this(defaultTag, handler = listOf()) + actual constructor( + defaultTag: String, + logLevelChecker: (LogLevel, String?) -> Boolean + ) : this( + defaultTag, + handler = listOf(), + logLevelChecker = logLevelChecker + ) companion object { private const val CALL_STACK_INDEX = 8 @@ -43,6 +51,8 @@ actual class DebugAntilog( LogLevel.ASSERT to "[ASSERT]" ) + override fun isEnable(priority: LogLevel, tag: String?): Boolean = logLevelChecker(priority, tag) + override fun performLog( priority: LogLevel, tag: String?,