diff --git a/CHANGELOG.md b/CHANGELOG.md index ae43510..c1b0446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 1.2.5 * Add `trace` logging level +* Change overall table of log level accordance +* Now you may change default platform logger ## 1.2.4 diff --git a/src/androidMain/AndroidManifest.xml b/src/androidMain/AndroidManifest.xml deleted file mode 100644 index 9b65eb0..0000000 --- a/src/androidMain/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/androidMain/kotlin/ActualLogger.kt b/src/androidMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt similarity index 77% rename from src/androidMain/kotlin/ActualLogger.kt rename to src/androidMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt index 8020f08..c55f39f 100644 --- a/src/androidMain/kotlin/ActualLogger.kt +++ b/src/androidMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -2,8 +2,7 @@ package dev.inmo.kslog.common import android.util.Log - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> val messageString = m.toString() when(l) { LogLevel.TRACE -> Log.d(t, messageString, e) @@ -14,4 +13,4 @@ internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, LogLevel.ERROR -> Log.e(t, messageString, e) LogLevel.ASSERT -> Log.wtf(t, messageString, e) } -} +} \ No newline at end of file diff --git a/src/commonMain/kotlin/DefaultKSLog.kt b/src/commonMain/kotlin/DefaultKSLog.kt index fca0638..4c290f1 100644 --- a/src/commonMain/kotlin/DefaultKSLog.kt +++ b/src/commonMain/kotlin/DefaultKSLog.kt @@ -3,7 +3,7 @@ package dev.inmo.kslog.common import dev.inmo.kslog.common.filter.filtered /** - * Logger based on [defaultLogging] or [logging] parameter + * Logger based on [KSLoggerDefaultPlatformLoggerLambda] or [logging] parameter * * @param defaultTag will be used in case when `tag` parameter in [performLog] omitted * @param messageFormatter special formatter which creating [String] inside of [performLog] for each call. Defaults to @@ -14,20 +14,20 @@ import dev.inmo.kslog.common.filter.filtered class DefaultKSLog( private val defaultTag: String, private val messageFormatter: MessageFormatter = defaultMessageFormatter, - private val logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = defaultLogging + private val logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = KSLoggerDefaultPlatformLoggerLambda ) : KSLog { override fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) { - val tag = tag ?: defaultTag + val resultTag = tag ?: defaultTag - val text = messageFormatter(level, tag, message, throwable) - logging(level, tag, text, throwable) + val text = messageFormatter(level, resultTag, message, throwable) + logging(level, resultTag, text, throwable) } override fun performLog(level: LogLevel, tag: String?, throwable: Throwable?, messageBuilder: () -> Any) { - val tag = tag ?: defaultTag + val resultTag = tag ?: defaultTag - val text = messageFormatter(level, tag, messageBuilder(), throwable) - logging(level, tag, text, throwable) + val text = messageFormatter(level, resultTag, messageBuilder(), throwable) + logging(level, resultTag, text, throwable) } override suspend fun performLogS( @@ -36,10 +36,10 @@ class DefaultKSLog( throwable: Throwable?, messageBuilder: suspend () -> Any ) { - val tag = tag ?: defaultTag + val resultTag = tag ?: defaultTag - val text = messageFormatter(level, tag, messageBuilder(), throwable) - logging(level, tag, text, throwable) + val text = messageFormatter(level, resultTag, messageBuilder(), throwable) + logging(level, resultTag, text, throwable) } } @@ -48,7 +48,7 @@ fun DefaultKSLog( defaultTag: String, filter: MessageFilter = { _, _, _ -> true }, messageFormatter: MessageFormatter = defaultMessageFormatter, - logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = defaultLogging + logging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = KSLoggerDefaultPlatformLoggerLambda ) = DefaultKSLog( defaultTag, messageFormatter, logging ).filtered(filter) diff --git a/src/commonMain/kotlin/KSLog.kt b/src/commonMain/kotlin/KSLog.kt index c19df1a..c964734 100644 --- a/src/commonMain/kotlin/KSLog.kt +++ b/src/commonMain/kotlin/KSLog.kt @@ -89,7 +89,6 @@ interface KSLog { operator fun KSLog.invoke(performLogCallback: (level: LogLevel, tag: String?, message: Any, throwable: Throwable?) -> Unit) = CallbackKSLog(performLogCallback) -internal expect val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit internal val printlnLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> println(defaultMessageFormatter(l, t, m, e)) } @@ -131,9 +130,9 @@ fun KSLog( levels: Iterable, messageFormatter: MessageFormatter = defaultMessageFormatter ): KSLog { - val levels = levels.toSet() + val levelsSet = levels.toSet() return KSLog (defaultTag, messageFormatter).filtered { l, _, _ -> - l in levels + l in levelsSet } } diff --git a/src/commonMain/kotlin/KSLoggerDefaultPlatformLoggerLambdaExpect.kt b/src/commonMain/kotlin/KSLoggerDefaultPlatformLoggerLambdaExpect.kt new file mode 100644 index 0000000..1b88c9d --- /dev/null +++ b/src/commonMain/kotlin/KSLoggerDefaultPlatformLoggerLambdaExpect.kt @@ -0,0 +1,7 @@ +package dev.inmo.kslog.common + +/** + * Default logger for current platform. You may change it, but you should remember that it is global logger + * used in [KSLog.default] by default + */ +expect var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit \ No newline at end of file diff --git a/src/jsMain/kotlin/ActualLogger.kt b/src/jsMain/kotlin/ActualLogger.kt deleted file mode 100644 index 19ed996..0000000 --- a/src/jsMain/kotlin/ActualLogger.kt +++ /dev/null @@ -1,16 +0,0 @@ -package dev.inmo.kslog.common - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> - val args = e ?.let { - arrayOf(m, e) - } ?: arrayOf(m) - when (l) { - LogLevel.TRACE, - LogLevel.DEBUG -> console.log(*args) - LogLevel.VERBOSE, - LogLevel.INFO -> console.info(*args) - LogLevel.WARNING -> console.warn(*args) - LogLevel.ERROR, - LogLevel.ASSERT -> console.error(*args) - } -} diff --git a/src/jsMain/kotlin/ExtendedConsole.kt b/src/jsMain/kotlin/ExtendedConsole.kt new file mode 100644 index 0000000..e486dc6 --- /dev/null +++ b/src/jsMain/kotlin/ExtendedConsole.kt @@ -0,0 +1,24 @@ +package dev.inmo.kslog.common + +import kotlin.js.Console + +external interface ExtendedConsole : Console { + fun trace() + fun debug(vararg o: Any?) + fun assert(vararg o: Any?) +} + +/** + * [https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static](https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static) + */ +fun Console.debug(vararg args: Any?) = unsafeCast().debug(*args) + +/** + * [https://developer.mozilla.org/en-US/docs/Web/APtraceI/console/assert_static](https://developer.mozilla.org/en-US/docs/Web/API/console/assert_static) + */ +fun Console.assert(vararg args: Any?) = unsafeCast().assert(*args) + +/** + * [https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static](https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static) + */ +fun Console.trace() = unsafeCast().trace() diff --git a/src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..3ae1d03 --- /dev/null +++ b/src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,19 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, _, m, e -> + val args = e ?.let { + arrayOf(m, e) + } ?: arrayOf(m) + when (l) { + LogLevel.TRACE -> { + console.trace() + console.debug(*args) + } + LogLevel.DEBUG -> console.debug(*args) + LogLevel.VERBOSE, + LogLevel.INFO -> console.info(*args) + LogLevel.WARNING -> console.warn(*args) + LogLevel.ERROR -> console.error(*args) + LogLevel.ASSERT -> console.assert(*args) + } +} \ No newline at end of file diff --git a/src/jvmMain/kotlin/ActualLogger.kt b/src/jvmMain/kotlin/ActualLogger.kt index c0c1b1e..71099f6 100644 --- a/src/jvmMain/kotlin/ActualLogger.kt +++ b/src/jvmMain/kotlin/ActualLogger.kt @@ -4,15 +4,15 @@ import dev.inmo.kslog.common.filter.filtered import java.util.logging.Level import java.util.logging.Logger -private val defaultKSLogLogger by lazy { +internal val defaultKSLogLogger by lazy { Logger.getLogger("KSLog") } -private fun Logger.doLog( +internal fun Logger.doLog( l: LogLevel, t: String, m: String, e: Throwable? ) = log( when(l) { - LogLevel.TRACE -> Level.ALL - LogLevel.DEBUG -> Level.FINEST + LogLevel.TRACE -> Level.FINEST + LogLevel.DEBUG -> Level.FINER LogLevel.VERBOSE -> Level.FINE LogLevel.INFO -> Level.INFO LogLevel.WARNING -> Level.WARNING @@ -22,9 +22,6 @@ private fun Logger.doLog( m, e ) -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> - defaultKSLogLogger.doLog(l, t, m.toString(), e) -} @Deprecated("Filtering should be replaced with FilterKSLog") fun KSLog( @@ -53,8 +50,8 @@ fun KSLog( levels: Iterable, messageFormatter: MessageFormatter = defaultMessageFormatter ): KSLog { - val levels = levels.toSet() - return KSLog (defaultTag, logger, messageFormatter).filtered { l, _, _ -> l in levels } + val levelsSet = levels.toSet() + return KSLog (defaultTag, logger, messageFormatter).filtered { l, _, _ -> l in levelsSet } } fun KSLog( diff --git a/src/jvmMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/jvmMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..8317513 --- /dev/null +++ b/src/jvmMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,5 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> + defaultKSLogLogger.doLog(l, t, m.toString(), e) +} \ No newline at end of file diff --git a/src/linuxArm32HfpMain/kotlin/DefaultLoggingActual.kt b/src/linuxArm32HfpMain/kotlin/DefaultLoggingActual.kt deleted file mode 100644 index 295deef..0000000 --- a/src/linuxArm32HfpMain/kotlin/DefaultLoggingActual.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.inmo.kslog.common - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit - get() = printlnLogging diff --git a/src/linuxArm32HfpMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/linuxArm32HfpMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..305d580 --- /dev/null +++ b/src/linuxArm32HfpMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,4 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = + printlnLogging \ No newline at end of file diff --git a/src/linuxArm64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/linuxArm64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..305d580 --- /dev/null +++ b/src/linuxArm64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,4 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = + printlnLogging \ No newline at end of file diff --git a/src/linuxArm64Main/kotlin/defaultLogging.kt b/src/linuxArm64Main/kotlin/defaultLogging.kt deleted file mode 100644 index 295deef..0000000 --- a/src/linuxArm64Main/kotlin/defaultLogging.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.inmo.kslog.common - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit - get() = printlnLogging diff --git a/src/linuxX64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/linuxX64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..305d580 --- /dev/null +++ b/src/linuxX64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,4 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = + printlnLogging \ No newline at end of file diff --git a/src/linuxX64Main/kotlin/defaultLogging.kt b/src/linuxX64Main/kotlin/defaultLogging.kt deleted file mode 100644 index 295deef..0000000 --- a/src/linuxX64Main/kotlin/defaultLogging.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.inmo.kslog.common - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit - get() = printlnLogging diff --git a/src/mingwX64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/mingwX64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..305d580 --- /dev/null +++ b/src/mingwX64Main/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,4 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = + printlnLogging \ No newline at end of file diff --git a/src/mingwX64Main/kotlin/defaultLogging.kt b/src/mingwX64Main/kotlin/defaultLogging.kt deleted file mode 100644 index 295deef..0000000 --- a/src/mingwX64Main/kotlin/defaultLogging.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.inmo.kslog.common - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit - get() = printlnLogging diff --git a/src/wasmJsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt b/src/wasmJsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt new file mode 100644 index 0000000..305d580 --- /dev/null +++ b/src/wasmJsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -0,0 +1,4 @@ +package dev.inmo.kslog.common + +actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = + printlnLogging \ No newline at end of file diff --git a/src/wasmJsMain/kotlin/defaultLogging.kt b/src/wasmJsMain/kotlin/defaultLogging.kt deleted file mode 100644 index 295deef..0000000 --- a/src/wasmJsMain/kotlin/defaultLogging.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.inmo.kslog.common - -internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit - get() = printlnLogging