From aad75a66b77970566c69e9342ec24da061d3583e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 7 Jun 2022 20:45:14 +0600 Subject: [PATCH] fixes --- build.gradle | 26 +------------------------- src/commonMain/kotlin/Extensions.kt | 9 ++++++++- src/commonMain/kotlin/Logger.kt | 6 +++--- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index b65051e..fd6c49d 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ repositories { kotlin { jvm() - js (IR) { + js(IR) { browser() nodejs() } @@ -47,30 +47,6 @@ 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 - } - } } } diff --git a/src/commonMain/kotlin/Extensions.kt b/src/commonMain/kotlin/Extensions.kt index 9949b6c..c0a3a5f 100644 --- a/src/commonMain/kotlin/Extensions.kt +++ b/src/commonMain/kotlin/Extensions.kt @@ -1,6 +1,8 @@ +@file:Suppress("NOTHING_TO_INLINE") + 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, 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 + +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(message: String, e: Throwable? = null) = verbose(message, e) inline fun Logger.v(tag: String, message: String, e: Throwable? = null) = verbose(tag, message, e) diff --git a/src/commonMain/kotlin/Logger.kt b/src/commonMain/kotlin/Logger.kt index e986e45..15dfd4a 100644 --- a/src/commonMain/kotlin/Logger.kt +++ b/src/commonMain/kotlin/Logger.kt @@ -11,10 +11,10 @@ enum class LogLevel { } 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 { 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) } @@ -23,7 +23,7 @@ interface Logger { class CallbackLogger( private val logger: (level: LogLevel, message: String, tag: String?, throwable: Throwable?) -> Unit ) : 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) }