diff --git a/src/commonMain/kotlin/AutoLoggers.kt b/src/commonMain/kotlin/AutoLoggers.kt index 88d9c0e..042013e 100644 --- a/src/commonMain/kotlin/AutoLoggers.kt +++ b/src/commonMain/kotlin/AutoLoggers.kt @@ -4,5 +4,5 @@ val Any.logTag get() = this::class.simpleName ?: error("Unable to retrieve log tag") val Any.logger get() = CallbackKSLog { l, t, m, e -> - KSLog.DEFAULT.performLog(l, t ?: logTag, m, e) + KSLog.default.performLog(l, t ?: logTag, m, e) } diff --git a/src/commonMain/kotlin/KSLog.kt b/src/commonMain/kotlin/KSLog.kt index 4a3741b..a8c0487 100644 --- a/src/commonMain/kotlin/KSLog.kt +++ b/src/commonMain/kotlin/KSLog.kt @@ -14,7 +14,7 @@ interface KSLog { fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) companion object : KSLog { private var defaultLogger: KSLog? = null - var DEFAULT: KSLog + var default: KSLog get() { return defaultLogger ?: KSLog("app").also { defaultLogger = it @@ -23,7 +23,7 @@ interface KSLog { set(value) { defaultLogger = value } - override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = DEFAULT.performLog(level, tag, message, throwable) + override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = default.performLog(level, tag, message, throwable) } } diff --git a/src/jsMain/kotlin/ActualLogger.kt b/src/jsMain/kotlin/ActualLogger.kt index e80dd52..1c74fcb 100644 --- a/src/jsMain/kotlin/ActualLogger.kt +++ b/src/jsMain/kotlin/ActualLogger.kt @@ -6,13 +6,16 @@ fun KSLog( ) = KSLog { l, t, m, e -> if (!filter(l, t, m, e)) return@KSLog val text = messageFormatter(l,t,m,e) + val args = e ?.let { + arrayOf(text, e) + } ?: arrayOf(text) when (l) { LogLevel.VERBOSE, - LogLevel.INFO -> console.info(text, e) - LogLevel.WARNING -> console.warn(text, e) + LogLevel.INFO -> console.info(*args) + LogLevel.WARNING -> console.warn(*args) LogLevel.ERROR, - LogLevel.ASSERT -> console.error(text, e) - LogLevel.DEBUG -> console.log(text, e) + LogLevel.ASSERT -> console.error(*args) + LogLevel.DEBUG -> console.log(*args) } }