This commit is contained in:
InsanusMokrassar 2022-06-07 20:45:14 +06:00
parent b47104227c
commit aad75a66b7
3 changed files with 12 additions and 29 deletions

View File

@ -47,30 +47,6 @@ kotlin {
implementation libs.kotlin implementation libs.kotlin
} }
} }
commonTest {
dependencies {
implementation libs.kotlin.test.common
implementation libs.kotlin.test.annotations.common
}
}
jvmTest {
dependencies {
implementation libs.kotlin.test.junit
}
}
jsTest {
dependencies {
implementation libs.kotlin.test.js
implementation libs.kotlin.test.junit
}
}
androidTest {
dependencies {
implementation libs.kotlin.test.junit
implementation libs.android.test.junit
implementation libs.android.test.espresso.core
}
}
} }
} }

View File

@ -1,6 +1,8 @@
@file:Suppress("NOTHING_TO_INLINE")
package dev.inmo.kslog.common package dev.inmo.kslog.common
inline fun Logger.log(level: LogLevel, tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(level, messageBuilder(), tag, e) inline fun Logger.log(level: LogLevel, tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = invoke(level, tag, messageBuilder(), e)
inline fun Logger.log(level: LogLevel, message: String, e: Throwable? = null) = log(level, null, e) { message } inline fun Logger.log(level: LogLevel, message: String, e: Throwable? = null) = log(level, null, e) { message }
inline fun Logger.log(level: LogLevel, tag: String, message: String, e: Throwable? = null) = log(level, tag, e) { message } inline fun Logger.log(level: LogLevel, tag: String, message: String, e: Throwable? = null) = log(level, tag, e) { message }
@ -36,6 +38,11 @@ inline fun Logger.debug(tag: String, message: String, e: Throwable? = null) = lo
// ----- Short names // ----- Short names
inline fun Logger.l(level: LogLevel, tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = log(level, tag, e, messageBuilder)
inline fun Logger.l(level: LogLevel, message: String, e: Throwable? = null) = log(level, message, e)
inline fun Logger.l(level: LogLevel, tag: String, message: String, e: Throwable? = null) = log(level, tag, message, e)
inline fun Logger.v(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = verbose(tag, e, messageBuilder) inline fun Logger.v(tag: String? = null, e: Throwable? = null, messageBuilder: () -> String) = verbose(tag, e, messageBuilder)
inline fun Logger.v(message: String, e: Throwable? = null) = verbose(message, e) inline fun Logger.v(message: String, e: Throwable? = null) = verbose(message, e)
inline fun Logger.v(tag: String, message: String, e: Throwable? = null) = verbose(tag, message, e) inline fun Logger.v(tag: String, message: String, e: Throwable? = null) = verbose(tag, message, e)

View File

@ -11,10 +11,10 @@ enum class LogLevel {
} }
interface Logger { interface Logger {
fun log (level: LogLevel, message: String, tag: String? = null, throwable: Throwable? = null) operator fun invoke(level: LogLevel, tag: String?, message: String, throwable: Throwable?)
companion object : Logger { companion object : Logger {
var DEFAULT: Logger = Logger("app") var DEFAULT: Logger = Logger("app")
override fun log(level: LogLevel, message: String, tag: String?, throwable: Throwable?) = DEFAULT.log(level, message, tag, throwable) override fun invoke(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = DEFAULT(level, tag, message, throwable)
operator fun invoke (log: (level: LogLevel, message: String, tag: String?, throwable: Throwable?) -> Unit) = CallbackLogger(log) operator fun invoke (log: (level: LogLevel, message: String, tag: String?, throwable: Throwable?) -> Unit) = CallbackLogger(log)
} }
@ -23,7 +23,7 @@ interface Logger {
class CallbackLogger( class CallbackLogger(
private val logger: (level: LogLevel, message: String, tag: String?, throwable: Throwable?) -> Unit private val logger: (level: LogLevel, message: String, tag: String?, throwable: Throwable?) -> Unit
) : Logger { ) : Logger {
override fun log(level: LogLevel, message: String, tag: String?, throwable: Throwable?) = logger(level, message, tag, throwable) override fun invoke(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = logger(level, message, tag, throwable)
} }