From 06b0da777a451cef5ac575e10a9e06a97801008c Mon Sep 17 00:00:00 2001 From: Sunny Chung Date: Wed, 17 Apr 2024 22:48:24 +0800 Subject: [PATCH] update `log` object to be a dedicated logger to avoid config overwriting other kermit users, and add `setKotliteStdlibLogMinLevel` global function --- interpreter/CHANGELOG.md | 1 + .../lib/multiplatform/kotlite/Globals.kt | 16 +++++++++++----- stdlib/CHANGELOG.md | 8 +++++++- .../multiplatform/kotlite/stdlib/StdlibGlobal.kt | 16 +++++++++++++--- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/interpreter/CHANGELOG.md b/interpreter/CHANGELOG.md index 9cba407..022f19a 100644 --- a/interpreter/CHANGELOG.md +++ b/interpreter/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Incorrect nullable resolution of extension properties - `IntRange.joinToString` yields incorrect string value - Function signature of `MutableMapValue` +- Logger is no longer a shared instance but a dedicated one ## [1.0.0] - 2024-04-08 diff --git a/interpreter/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/Globals.kt b/interpreter/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/Globals.kt index b4a3e9b..8eb367e 100644 --- a/interpreter/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/Globals.kt +++ b/interpreter/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/Globals.kt @@ -1,13 +1,19 @@ package com.sunnychung.lib.multiplatform.kotlite +import co.touchlab.kermit.LogWriter import co.touchlab.kermit.Logger +import co.touchlab.kermit.MutableLoggerConfig import co.touchlab.kermit.Severity +import co.touchlab.kermit.platformLogWriter -internal val log = Logger.apply { - setTag("kotlite") - setMinSeverity(Severity.Info) -} +internal val log = Logger( + config = object : MutableLoggerConfig { + override var logWriterList: List = listOf(platformLogWriter()) + override var minSeverity: Severity = Severity.Info + }, + tag = "kotlite", +) fun setKotliteLogMinLevel(severity: Severity) { - log.setMinSeverity(severity) + (log.config as MutableLoggerConfig).minSeverity = severity } diff --git a/stdlib/CHANGELOG.md b/stdlib/CHANGELOG.md index bd7c772..5ae08f4 100644 --- a/stdlib/CHANGELOG.md +++ b/stdlib/CHANGELOG.md @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -Nothing yet. +### Added + +- Global function `setKotliteStdlibLogMinLevel(severity: Severity)` + +### Fixed + +- Logger is no longer a shared instance but a dedicated one ## [1.0.0] - 2024-04-08 diff --git a/stdlib/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/stdlib/StdlibGlobal.kt b/stdlib/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/stdlib/StdlibGlobal.kt index 33ad6fd..778cf43 100644 --- a/stdlib/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/stdlib/StdlibGlobal.kt +++ b/stdlib/src/commonMain/kotlin/com/sunnychung/lib/multiplatform/kotlite/stdlib/StdlibGlobal.kt @@ -1,9 +1,19 @@ package com.sunnychung.lib.multiplatform.kotlite.stdlib +import co.touchlab.kermit.LogWriter import co.touchlab.kermit.Logger +import co.touchlab.kermit.MutableLoggerConfig import co.touchlab.kermit.Severity +import co.touchlab.kermit.platformLogWriter -internal val log = Logger.apply { - setTag("kotlite-stdlib") - setMinSeverity(Severity.Info) +internal val log = Logger( + config = object : MutableLoggerConfig { + override var logWriterList: List = listOf(platformLogWriter()) + override var minSeverity: Severity = Severity.Info + }, + tag = "kotlite-stdlib", +) + +fun setKotliteStdlibLogMinLevel(severity: Severity) { + (log.config as MutableLoggerConfig).minSeverity = severity }