diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ff044..405dd52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 1.3.0 + +**THIS UPDATE CONTAINS CHANGES OF LOG LEVELS ACCORDANCES. LOOK AT THE LEVELS ACCORDANCE IN THE [DOCUMENTATION](https://docs.inmo.dev/kslog/logging.html#logging) +FOR MORE INFO** + +* Add `trace` logging level +* Change overall table of log level accordance +* Now you may change default platform logger + ## 1.2.4 **This update contains migration onto gradle 8+ (for both wrapper and android plugin). Use it with caution** diff --git a/gradle.properties b/gradle.properties index d323db5..0df54d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,5 +10,5 @@ org.gradle.jvmargs=-Xmx512m # Project data group=dev.inmo -version=1.2.4 -android_code_version=26 +version=1.3.0 +android_code_version=27 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 972c8f1..fd5bf12 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,9 @@ [versions] kotlin = "1.9.20" -kotlin-gradle-plugin = "8.1.2" +kotlin-gradle-plugin = "8.1.4" -versions = "0.49.0" +versions = "0.50.0" dokka = "1.9.10" 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 69% rename from src/androidMain/kotlin/ActualLogger.kt rename to src/androidMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt index 8a37e03..c55f39f 100644 --- a/src/androidMain/kotlin/ActualLogger.kt +++ b/src/androidMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt @@ -2,10 +2,10 @@ 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) LogLevel.DEBUG -> Log.d(t, messageString, e) LogLevel.VERBOSE -> Log.v(t, messageString, e) LogLevel.INFO -> Log.i(t, messageString, e) @@ -13,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/AutoLoggers.kt b/src/commonMain/kotlin/AutoLoggers.kt index 99128a2..1ada132 100644 --- a/src/commonMain/kotlin/AutoLoggers.kt +++ b/src/commonMain/kotlin/AutoLoggers.kt @@ -1,8 +1,20 @@ package dev.inmo.kslog.common +/** + * Creating base tag using class simple name of receiver + * + * @throws IllegalStateException If there is no opportunity to take simple name of receiver class + */ val Any.logTag get() = this::class.simpleName ?: error("Unable to retrieve log tag") + +/** + * Creating [TagLogger] with [logTag] as base tag + */ val Any.logger: KSLog get() = TagLogger(logTag) +/** + * Creating [TagLogger] using [logger] extension property with [tagBase] as `this` + */ fun taggedLogger(tagBase: Any): KSLog = tagBase.logger diff --git a/src/commonMain/kotlin/CallbackKSLog.kt b/src/commonMain/kotlin/CallbackKSLog.kt index 4a43b34..d785ea5 100644 --- a/src/commonMain/kotlin/CallbackKSLog.kt +++ b/src/commonMain/kotlin/CallbackKSLog.kt @@ -1,13 +1,22 @@ package dev.inmo.kslog.common +import kotlin.jvm.JvmInline + typealias SimpleKSLogCallback = (level: LogLevel, tag: String?, message: Any, throwable: Throwable?) -> Unit -class CallbackKSLog( +/** + * Creates simple [KSLog] which will pass all incoming [performLog] calls to [performLogCallback] + */ +@JvmInline +value class CallbackKSLog( private val performLogCallback: SimpleKSLogCallback ) : KSLog { override fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) = performLogCallback(level, tag, message, throwable) } +/** + * Creating [CallbackKSLog] using [performLogCallback] as an argument for constructor + */ fun KSLog( performLogCallback: SimpleKSLogCallback ) = CallbackKSLog(performLogCallback) diff --git a/src/commonMain/kotlin/DefaultKSLog.kt b/src/commonMain/kotlin/DefaultKSLog.kt index 823fd3d..4c290f1 100644 --- a/src/commonMain/kotlin/DefaultKSLog.kt +++ b/src/commonMain/kotlin/DefaultKSLog.kt @@ -2,23 +2,32 @@ package dev.inmo.kslog.common import dev.inmo.kslog.common.filter.filtered +/** + * 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 + * [defaultMessageFormatter] + * @param logging target lambda which will be called with a result of [messageFormatter] logs formatting as a message + * and tag as tag if not `null` and [defaultTag] otherwise + */ 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( @@ -27,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) } } @@ -39,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/Extensions.kt b/src/commonMain/kotlin/Extensions.kt index ae73e61..4110a9c 100644 --- a/src/commonMain/kotlin/Extensions.kt +++ b/src/commonMain/kotlin/Extensions.kt @@ -15,6 +15,19 @@ inline fun KSLog.log(level: LogLevel, tag: String, message: Any, e: Throwable?) inline fun KSLog.log(level: LogLevel, tag: String, message: Any) = performLog(level, tag, message, null) +inline fun KSLog.trace(e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.TRACE, null, e, messageBuilder) +inline fun KSLog.trace(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.TRACE, tag, e, messageBuilder) +inline fun KSLog.trace(tag: String, noinline messageBuilder: () -> Any) = trace(tag, null, messageBuilder) +suspend inline fun KSLog.traceS(e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = logS(LogLevel.TRACE, null, e, messageBuilder) +suspend inline fun KSLog.traceS(tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = logS(LogLevel.TRACE, tag, e, messageBuilder) +suspend inline fun KSLog.traceS(tag: String, noinline messageBuilder: suspend () -> Any) = traceS(tag, null, messageBuilder) +inline fun KSLog.trace(message: Any, e: Throwable?) = log(LogLevel.TRACE, message, e) +inline fun KSLog.trace(message: String, e: Throwable) = trace(message as Any, e) +inline fun KSLog.trace(message: Any) = trace(message, null) +inline fun KSLog.trace(tag: String, message: Any, e: Throwable?) = log(LogLevel.TRACE, tag, message, e) +inline fun KSLog.trace(tag: String, message: Any) = trace(tag, message, null) + + inline fun KSLog.debug(e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.DEBUG, null, e, messageBuilder) inline fun KSLog.debug(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.DEBUG, tag, e, messageBuilder) inline fun KSLog.debug(tag: String, noinline messageBuilder: () -> Any) = debug(tag, null, messageBuilder) @@ -108,6 +121,19 @@ inline fun KSLog.l(level: LogLevel, tag: String, message: Any, e: Throwable?) = inline fun KSLog.l(level: LogLevel, tag: String, message: Any) = log(level, tag, message, null) +inline fun KSLog.t(e: Throwable? = null, noinline messageBuilder: () -> Any) = trace(e, messageBuilder) +inline fun KSLog.t(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = trace(tag, e, messageBuilder) +inline fun KSLog.t(tag: String, noinline messageBuilder: () -> Any) = t(tag, null, messageBuilder) +suspend inline fun KSLog.tS(e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = traceS(e, messageBuilder) +suspend inline fun KSLog.tS(tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = traceS(tag, e, messageBuilder) +suspend inline fun KSLog.tS(tag: String, noinline messageBuilder: suspend () -> Any) = tS(tag, null, messageBuilder) +inline fun KSLog.t(message: Any, e: Throwable?) = trace(message, e) +inline fun KSLog.t(message: String, e: Throwable) = t(message as Any, e) +inline fun KSLog.t(message: Any) = t(message, null) +inline fun KSLog.t(tag: String, message: Any, e: Throwable?) = trace(tag, message, e) +inline fun KSLog.t(tag: String, message: Any) = t(tag, message, null) + + inline fun KSLog.d(e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(e, messageBuilder) inline fun KSLog.d(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(tag, e, messageBuilder) inline fun KSLog.d(tag: String, noinline messageBuilder: () -> Any) = d(tag, null, messageBuilder) diff --git a/src/commonMain/kotlin/KSLog.kt b/src/commonMain/kotlin/KSLog.kt index c00e141..c964734 100644 --- a/src/commonMain/kotlin/KSLog.kt +++ b/src/commonMain/kotlin/KSLog.kt @@ -5,6 +5,7 @@ import dev.inmo.kslog.common.utils.plus enum class LogLevel { + TRACE, DEBUG, VERBOSE, INFO, @@ -13,15 +14,38 @@ enum class LogLevel { ASSERT, } +/** + * Base interface for any logger + * + * @see default + * + */ interface KSLog { + /** + * The only one function required to realization in any inheritor. All other [performLog] functions + * will call this one by default + */ fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) + + /** + * Calls default [performLog] with `tag` == `null` + */ fun performLog(level: LogLevel, message: Any, throwable: Throwable?) = performLog(level, null, message, throwable) + /** + * Calls default [performLog] with `message` built using [messageBuilder]. This method supposed to be overriden in + * case when logger supports lazy-loaded messages (like [dev.inmo.kslog.common.filter.FilterKSLog]) + */ fun performLog( level: LogLevel, tag: String?, throwable: Throwable?, messageBuilder: () -> Any ) = performLog(level, tag, messageBuilder(), throwable) + + /** + * Suspendable variant of [performLog] with [messageBuilder]. Uses default [performLog] with `message` built using + * [messageBuilder] by default + */ suspend fun performLogS( level: LogLevel, tag: String?, @@ -65,15 +89,20 @@ 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)) } +/** + * Simple builder for [DefaultKSLog] logger based on [defaultTag] + */ fun KSLog( defaultTag: String, ): KSLog = DefaultKSLog(defaultTag) +/** + * Simple builder for [DefaultKSLog] logger based on [defaultTag] and [messageFormatter] + */ fun KSLog( defaultTag: String, messageFormatter: MessageFormatter @@ -92,17 +121,25 @@ fun KSLog( messageFormatter ).filtered(filter) +/** + * Building logger using [KSLog] builder based on [defaultTag] and [messageFormatter]. This logger will also filter + * incoming levels: only levels passed in [levels] param will be logged + */ fun KSLog( defaultTag: String, 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 } } +/** + * Building logger using [KSLog] builder based on [defaultTag] and [messageFormatter]. This logger will also filter + * incoming levels: only levels passed in [firstLevel], [secondLevel] and [otherLevels] param will be logged + */ fun KSLog( defaultTag: String, firstLevel: LogLevel, @@ -111,6 +148,10 @@ fun KSLog( messageFormatter: MessageFormatter = defaultMessageFormatter, ): KSLog = KSLog(defaultTag, setOf(firstLevel, secondLevel, *otherLevels), messageFormatter) +/** + * Building logger using [KSLog] builder based on [defaultTag] and [messageFormatter]. This logger will also filter + * incoming levels: only levels above [minLoggingLevel] will be logged + */ fun KSLog( defaultTag: String, minLoggingLevel: LogLevel, @@ -122,5 +163,13 @@ fun KSLog( minLoggingLevel.ordinal <= l.ordinal } +/** + * Setting [KSLog.default] logger to [newDefault] + */ fun setDefaultKSLog(newDefault: KSLog) { KSLog.default = newDefault } -fun addDefaultKSLog(newDefault: KSLog) { KSLog.default = KSLog.default + newDefault } +/** + * Setting [KSLog.default] logger to new [CallbackKSLog] using [plus] operation + */ +fun addDefaultKSLog(newDefault: KSLog) { + KSLog.default += newDefault +} diff --git a/src/commonMain/kotlin/KSLogTypealiases.kt b/src/commonMain/kotlin/KSLogTypealiases.kt index 5660ae0..1d55ad4 100644 --- a/src/commonMain/kotlin/KSLogTypealiases.kt +++ b/src/commonMain/kotlin/KSLogTypealiases.kt @@ -1,7 +1,6 @@ package dev.inmo.kslog.common typealias MessageFormatter = (l: LogLevel, t: String?, m: Any, Throwable?) -> String -@Suppress("NOTHING_TO_INLINE") inline fun MessageFormatter(noinline formatter: MessageFormatter) = formatter typealias MessageFilter = (l: LogLevel, t: String?, Throwable?) -> Boolean val defaultMessageFormatter: MessageFormatter = { l, t, m, _ -> "[$l] ${t ?.let { "$it " } ?: ""}- $m" } 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/commonMain/kotlin/TagLogger.kt b/src/commonMain/kotlin/TagLogger.kt index 123c5dd..278a75b 100644 --- a/src/commonMain/kotlin/TagLogger.kt +++ b/src/commonMain/kotlin/TagLogger.kt @@ -2,6 +2,9 @@ package dev.inmo.kslog.common import kotlin.jvm.JvmInline +/** + * Logger which will use [tag] as default one in cases when [performLog] have `null` tag + */ @JvmInline value class TagLogger(val tag: String) : KSLog { override fun performLog(level: LogLevel, tag: String?, message: Any, throwable: Throwable?) { diff --git a/src/commonMain/kotlin/filter/FilterKSLog.kt b/src/commonMain/kotlin/filter/FilterKSLog.kt index d369a6c..470dbf3 100644 --- a/src/commonMain/kotlin/filter/FilterKSLog.kt +++ b/src/commonMain/kotlin/filter/FilterKSLog.kt @@ -2,6 +2,10 @@ package dev.inmo.kslog.common.filter import dev.inmo.kslog.common.* +/** + * In its [performLog]/[performLogS] methods do logging only in cases when [messageFilter] returns true for incoming + * parameters + */ class FilterKSLog( private val fallbackLogger: KSLog, private val messageFilter: MessageFilter diff --git a/src/commonMain/kotlin/filter/FilteredExtension.kt b/src/commonMain/kotlin/filter/FilteredExtension.kt index 443ea50..94b085d 100644 --- a/src/commonMain/kotlin/filter/FilteredExtension.kt +++ b/src/commonMain/kotlin/filter/FilteredExtension.kt @@ -3,6 +3,9 @@ package dev.inmo.kslog.common.filter import dev.inmo.kslog.common.KSLog import dev.inmo.kslog.common.MessageFilter +/** + * Creates [FilterKSLog] with applying of [filter] to it + */ fun KSLog.filtered( filter: MessageFilter ) = FilterKSLog(this, filter) diff --git a/src/commonMain/kotlin/typed/TypedKSLog.kt b/src/commonMain/kotlin/typed/TypedKSLog.kt index eab822f..bd15239 100644 --- a/src/commonMain/kotlin/typed/TypedKSLog.kt +++ b/src/commonMain/kotlin/typed/TypedKSLog.kt @@ -3,6 +3,11 @@ package dev.inmo.kslog.common.typed import dev.inmo.kslog.common.* import kotlin.reflect.KClass +/** + * Uses [typedLoggers] [Map] to determine, where incoming __message__s should be sent. If there is no [KClass] key for + * incoming message in [typedLoggers], logger will use logger by `null` key if exists. If there is no default logger + * (by `null` key), logging will be skipped + */ class TypedKSLog( private val typedLoggers: Map?, KSLog> ) : KSLog { diff --git a/src/commonMain/kotlin/typed/TypedKSLogBuilder.kt b/src/commonMain/kotlin/typed/TypedKSLogBuilder.kt index ee93e4a..075cfe5 100644 --- a/src/commonMain/kotlin/typed/TypedKSLogBuilder.kt +++ b/src/commonMain/kotlin/typed/TypedKSLogBuilder.kt @@ -3,6 +3,9 @@ package dev.inmo.kslog.common.typed import dev.inmo.kslog.common.* import kotlin.reflect.KClass +/** + * Special builder for [TypedKSLog] + */ class TypedKSLogBuilder( private val preset: Map?, KSLog> = emptyMap() ) { @@ -22,6 +25,9 @@ class TypedKSLogBuilder( fun build() = TypedKSLog(loggers.toMap()) } +/** + * DSL for [TypedKSLogBuilder] + */ inline fun buildTypedLogger( preset: Map?, KSLog> = emptyMap(), block: TypedKSLogBuilder.() -> Unit diff --git a/src/commonMain/kotlin/utils/Combination.kt b/src/commonMain/kotlin/utils/Combination.kt index cee2897..543d121 100644 --- a/src/commonMain/kotlin/utils/Combination.kt +++ b/src/commonMain/kotlin/utils/Combination.kt @@ -3,6 +3,10 @@ package dev.inmo.kslog.common.utils import dev.inmo.kslog.common.CallbackKSLog import dev.inmo.kslog.common.KSLog +/** + * Will send [KSLog.performLog] of both [this] and [other] [KSLog] instances. In case when [this] will throw exception + * result logger will rethrow it. After it, if [other] will throw exception - will also rethrow it + */ infix operator fun KSLog.plus(other: KSLog) = CallbackKSLog { l, t, m, e -> val resultOfFirst = runCatching { this@plus.performLog(l, t, m, e) diff --git a/src/jsMain/kotlin/ActualLogger.kt b/src/jsMain/kotlin/ActualLogger.kt deleted file mode 100644 index c647d75..0000000 --- a/src/jsMain/kotlin/ActualLogger.kt +++ /dev/null @@ -1,15 +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.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 aa3ac13..71099f6 100644 --- a/src/jvmMain/kotlin/ActualLogger.kt +++ b/src/jvmMain/kotlin/ActualLogger.kt @@ -4,14 +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.DEBUG -> Level.FINEST + LogLevel.TRACE -> Level.FINEST + LogLevel.DEBUG -> Level.FINER LogLevel.VERBOSE -> Level.FINE LogLevel.INFO -> Level.INFO LogLevel.WARNING -> Level.WARNING @@ -21,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( @@ -52,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