From 08ac9d92fcd7308ed328dbde59f81acd79682d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Thu, 3 Apr 2025 14:24:40 +0200 Subject: [PATCH] feat(logger): Deprecate and scrap the Logger library --- logger/README.ios.md | 3 -- logger/README.js.md | 3 -- logger/README.jvm.md | 3 -- logger/README.linuxX64.md | 3 -- logger/README.md | 12 +++-- logger/build.gradle.kts | 22 +++++--- logger/src/commonMain/kotlin/Deprecation.kt | 19 +++++++ logger/src/commonMain/kotlin/LogLevel.kt | 1 + logger/src/commonMain/kotlin/Logger.kt | 35 ++++++++++++- logger/src/iosMain/kotlin/Logger.kt | 53 ------------------- logger/src/jsMain/kotlin/Logger.kt | 43 --------------- logger/src/jvmMain/kotlin/Logger.kt | 58 --------------------- logger/src/linuxX64Main/kotlin/Logger.kt | 49 ----------------- 13 files changed, 79 insertions(+), 225 deletions(-) delete mode 100644 logger/README.ios.md delete mode 100644 logger/README.js.md delete mode 100644 logger/README.jvm.md delete mode 100644 logger/README.linuxX64.md create mode 100644 logger/src/commonMain/kotlin/Deprecation.kt delete mode 100644 logger/src/iosMain/kotlin/Logger.kt delete mode 100644 logger/src/jsMain/kotlin/Logger.kt delete mode 100644 logger/src/jvmMain/kotlin/Logger.kt delete mode 100644 logger/src/linuxX64Main/kotlin/Logger.kt diff --git a/logger/README.ios.md b/logger/README.ios.md deleted file mode 100644 index 37e3a41..0000000 --- a/logger/README.ios.md +++ /dev/null @@ -1,3 +0,0 @@ -# Module Logger - -Logger implementation that delegates to [os_log](https://developer.apple.com/documentation/os/os_log). diff --git a/logger/README.js.md b/logger/README.js.md deleted file mode 100644 index 18ff3e7..0000000 --- a/logger/README.js.md +++ /dev/null @@ -1,3 +0,0 @@ -# Module Logger - -Logger implementation that delegates to the [browser's console](https://developer.mozilla.org/en-US/docs/Web/API/console). diff --git a/logger/README.jvm.md b/logger/README.jvm.md deleted file mode 100644 index c01a116..0000000 --- a/logger/README.jvm.md +++ /dev/null @@ -1,3 +0,0 @@ -# Module Logger - -Logger implementation that delegates to [Slf4j](https://www.slf4j.org/). diff --git a/logger/README.linuxX64.md b/logger/README.linuxX64.md deleted file mode 100644 index a725806..0000000 --- a/logger/README.linuxX64.md +++ /dev/null @@ -1,3 +0,0 @@ -# Module Logger - -Logger implementation that prints to the program's standard output. diff --git a/logger/README.md b/logger/README.md index 97ac0be..f7ff145 100644 --- a/logger/README.md +++ b/logger/README.md @@ -1,12 +1,18 @@ -# Module Logger +# Module Logger (DEPRECATED) Simple multiplatform [Logger][opensavvy.logger.Logger] interface that delegates to the logging facilities of the underlying platform. - + -Example usage: +## Deprecation warning + +This library has been deprecated. For now, all implementations have fallen back to using the standard library's `println`. No more useful versions will be published. We do not plan on adding any new features, but the library won't be removed to avoid breaking existing projects. + +If you are using this library, we encourage to migrate to other more popular logging libraries, like KotlinLogging. + +## Usage ```kotlin import opensavvy.logger.loggerFor diff --git a/logger/build.gradle.kts b/logger/build.gradle.kts index 50404b5..dbada9b 100644 --- a/logger/build.gradle.kts +++ b/logger/build.gradle.kts @@ -1,4 +1,18 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask +/* + * Copyright (c) 2025, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ plugins { alias(opensavvyConventions.plugins.base) @@ -26,7 +40,7 @@ kotlin { } library { - name.set("Logger") + name.set("Logger (DEPRECATED)") description.set("Simple multiplatform logger") homeUrl.set("https://opensavvy.gitlab.io/groundwork/pedestal/api-docs/logger/index.html") @@ -35,7 +49,3 @@ library { url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") } } - -tasks.withType(KotlinCompilationTask::class) { - compilerOptions.freeCompilerArgs.add("-opt-in=kotlinx.cinterop.ExperimentalForeignApi") -} diff --git a/logger/src/commonMain/kotlin/Deprecation.kt b/logger/src/commonMain/kotlin/Deprecation.kt new file mode 100644 index 0000000..607ba12 --- /dev/null +++ b/logger/src/commonMain/kotlin/Deprecation.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.logger + +internal const val DEPRECATION_MESSAGE = "The OpenSavvy Logger library is deprecated and won't be maintained anymore. We do not plan on deleting the library, but we do not plan on improving it either. We encourage you to switch to another logging library." diff --git a/logger/src/commonMain/kotlin/LogLevel.kt b/logger/src/commonMain/kotlin/LogLevel.kt index 9fa8642..3e166c3 100644 --- a/logger/src/commonMain/kotlin/LogLevel.kt +++ b/logger/src/commonMain/kotlin/LogLevel.kt @@ -16,6 +16,7 @@ package opensavvy.logger +@Deprecated(DEPRECATION_MESSAGE) enum class LogLevel { // The order of the elements is important TRACE, diff --git a/logger/src/commonMain/kotlin/Logger.kt b/logger/src/commonMain/kotlin/Logger.kt index d659703..7d0151f 100644 --- a/logger/src/commonMain/kotlin/Logger.kt +++ b/logger/src/commonMain/kotlin/Logger.kt @@ -77,6 +77,7 @@ import opensavvy.logger.Logger.Companion.warn * On Kotlin/JS, it uses the `console` object. * On Kotlin/JVM, it uses the [Slf4j](https://www.slf4j.org/) library, you will need to include a Slf4j binding in your project. */ +@Deprecated(DEPRECATION_MESSAGE) interface Logger { /** @@ -86,6 +87,7 @@ interface Logger { * additionally to this attribute. * For example, LogBack has its own log level configuration, Slf4j-simple never prints trace and debug messages. */ + @Deprecated(DEPRECATION_MESSAGE) var level: LogLevel fun forceTrace(message: String, vararg objects: Any?) @@ -122,4 +124,35 @@ interface Logger { } } -expect fun loggerFor(obj: Any): Logger +@Deprecated(DEPRECATION_MESSAGE) +fun loggerFor(obj: Any): Logger = + VerySimpleLogger(obj) + +private class VerySimpleLogger(private val obj: Any) : Logger { + override var level: LogLevel = LogLevel.default + + private val objName = obj::class.toString() + + private fun buildMessage(vararg values: Any?) = + values.joinToString(separator = " • ") + + override fun forceTrace(message: String, vararg objects: Any?) { + println("[TRACE] $objName: ${buildMessage(message, *objects)}") + } + + override fun forceDebug(message: String, vararg objects: Any?) { + println("[DEBUG] $objName: ${buildMessage(message, *objects)}") + } + + override fun forceInfo(message: String, vararg objects: Any?) { + println("[INFO] $objName: ${buildMessage(message, *objects)}") + } + + override fun forceWarn(message: String, vararg objects: Any?) { + println("[WARN] $objName: ${buildMessage(message, *objects)}") + } + + override fun forceError(message: String, vararg objects: Any?) { + println("[ERROR] $objName: ${buildMessage(message, *objects)}") + } +} diff --git a/logger/src/iosMain/kotlin/Logger.kt b/logger/src/iosMain/kotlin/Logger.kt deleted file mode 100644 index a015ae9..0000000 --- a/logger/src/iosMain/kotlin/Logger.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2023-2025, OpenSavvy and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package opensavvy.logger - -import kotlinx.cinterop.ptr -import platform.darwin.* - -class IosLogger(self: Any): Logger { - override var level = LogLevel.default - - private val tag = self::class.simpleName - - override fun forceTrace(message: String, vararg objects: Any?) { - val string = "$tag: $message ${objects.joinToString(" ")}" - _os_log_internal(__dso_handle.ptr, OS_LOG_DEFAULT, OS_LOG_TYPE_DEFAULT, "%s", string) - } - - override fun forceDebug(message: String, vararg objects: Any?) { - val string = "$tag: $message ${objects.joinToString(" ")}" - _os_log_internal(__dso_handle.ptr, OS_LOG_DEFAULT, OS_LOG_TYPE_DEBUG, "%s", string) - } - - override fun forceInfo(message: String, vararg objects: Any?) { - val string = "$tag: $message ${objects.joinToString(" ")}" - _os_log_internal(__dso_handle.ptr, OS_LOG_DEFAULT, OS_LOG_TYPE_INFO, "%s", string) - } - - override fun forceWarn(message: String, vararg objects: Any?) { - val string = "$tag: $message ${objects.joinToString(" ")}" - _os_log_internal(__dso_handle.ptr, OS_LOG_DEFAULT, OS_LOG_TYPE_DEFAULT, "%s", string) - } - - override fun forceError(message: String, vararg objects: Any?) { - val string = "$tag: $message ${objects.joinToString(" ")}" - _os_log_internal(__dso_handle.ptr, OS_LOG_DEFAULT, OS_LOG_TYPE_ERROR, "%s", string) - } -} - -actual fun loggerFor(obj: Any): Logger = IosLogger(obj) diff --git a/logger/src/jsMain/kotlin/Logger.kt b/logger/src/jsMain/kotlin/Logger.kt deleted file mode 100644 index cbc796c..0000000 --- a/logger/src/jsMain/kotlin/Logger.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022-2025, OpenSavvy and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package opensavvy.logger - -private class ConsoleLogger(private val self: Any) : Logger { - override var level = LogLevel.default - - override fun forceTrace(message: String, vararg objects: Any?) { - console.log(self::class.simpleName, message, *objects) - } - - override fun forceDebug(message: String, vararg objects: Any?) { - console.log(self::class.simpleName, message, *objects) - } - - override fun forceInfo(message: String, vararg objects: Any?) { - console.info(self::class.simpleName, message, *objects) - } - - override fun forceWarn(message: String, vararg objects: Any?) { - console.warn(self::class.simpleName, message, *objects) - } - - override fun forceError(message: String, vararg objects: Any?) { - console.error(self::class.simpleName, message, *objects) - } -} - -actual fun loggerFor(obj: Any): Logger = ConsoleLogger(obj) diff --git a/logger/src/jvmMain/kotlin/Logger.kt b/logger/src/jvmMain/kotlin/Logger.kt deleted file mode 100644 index 9cdd99b..0000000 --- a/logger/src/jvmMain/kotlin/Logger.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022-2025, OpenSavvy and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package opensavvy.logger - -import org.slf4j.LoggerFactory - -private class SlfLogger(self: Any) : Logger { - override var level = LogLevel.default - private val logger = LoggerFactory.getLogger(self::class.java) - ?: error("Could not find a logger for ${self::class.java}") - - private fun generateFormat(message: String, vararg objects: Any?): String { - var result = message - - repeat(objects.size) { - result += " {}" - } - - return result - } - - override fun forceTrace(message: String, vararg objects: Any?) { - logger.trace(generateFormat(message, *objects), *objects) - } - - override fun forceDebug(message: String, vararg objects: Any?) { - logger.debug(generateFormat(message, *objects), *objects) - } - - override fun forceInfo(message: String, vararg objects: Any?) { - logger.info(generateFormat(message, *objects), *objects) - } - - override fun forceWarn(message: String, vararg objects: Any?) { - logger.warn(generateFormat(message, *objects), *objects) - } - - override fun forceError(message: String, vararg objects: Any?) { - logger.error(generateFormat(message, *objects), *objects) - } - -} - -actual fun loggerFor(obj: Any): Logger = SlfLogger(obj) diff --git a/logger/src/linuxX64Main/kotlin/Logger.kt b/logger/src/linuxX64Main/kotlin/Logger.kt deleted file mode 100644 index ffcf3b0..0000000 --- a/logger/src/linuxX64Main/kotlin/Logger.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2023-2025, OpenSavvy and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package opensavvy.logger - -private class LinuxLogger(obj: Any) : Logger { - override var level: LogLevel = LogLevel.default - - private val objName = obj::class.qualifiedName ?: obj::class.toString() - - private fun buildMessage(vararg values: Any?) = - values.joinToString(separator = " • ") - - override fun forceTrace(message: String, vararg objects: Any?) { - println("[TRACE] $objName: ${buildMessage(message, *objects)}") - } - - override fun forceDebug(message: String, vararg objects: Any?) { - println("[DEBUG] $objName: ${buildMessage(message, *objects)}") - } - - override fun forceInfo(message: String, vararg objects: Any?) { - println("[INFO] $objName: ${buildMessage(message, *objects)}") - } - - override fun forceWarn(message: String, vararg objects: Any?) { - println("[WARN] $objName: ${buildMessage(message, *objects)}") - } - - override fun forceError(message: String, vararg objects: Any?) { - println("[ERROR] $objName: ${buildMessage(message, *objects)}") - } -} - -actual fun loggerFor(obj: Any): Logger = - LinuxLogger(obj) -- 2.51.2