new: extract logging module into standalone core library

This commit is contained in:
2026-06-19 17:35:12 +02:00
parent c4572eb042
commit 77a8ee645f
5 changed files with 54 additions and 4 deletions
+49
View File
@@ -0,0 +1,49 @@
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidMultiplatformLibrary)
}
kotlin {
iosArm64()
iosSimulatorArm64()
jvm()
js {
browser()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
}
androidLibrary {
namespace = "fr.ajaury.gwenedeg.core.logging"
compileSdk =
libs.versions.androidCompileSdk
.get()
.toInt()
minSdk =
libs.versions.androidMinSdk
.get()
.toInt()
compilerOptions {
jvmTarget = JvmTarget.JVM_11
}
}
sourceSets {
commonMain.dependencies {
// Logging
implementation(libs.kermit)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
}
}
@@ -0,0 +1,26 @@
package fr.ajaury.gwenedeg.core.logging
import co.touchlab.kermit.Logger as Kermit
/**
* Kermit-backed implementation (adapter) of the [Logger] port.
*/
class KermitLogger(
private val tag: String = "Gwenedeg",
) : Logger {
override fun debug(message: String, throwable: Throwable?) {
Kermit.d(throwable = throwable, tag = tag) { message }
}
override fun info(message: String, throwable: Throwable?) {
Kermit.i(throwable = throwable, tag = tag) { message }
}
override fun warning(message: String, throwable: Throwable?) {
Kermit.w(throwable = throwable, tag = tag) { message }
}
override fun error(message: String, throwable: Throwable?) {
Kermit.e(throwable = throwable, tag = tag) { message }
}
}
@@ -0,0 +1,27 @@
package fr.ajaury.gwenedeg.core.logging
/**
* Logging abstraction so the rest of the app depends on this interface
* rather than on a concrete logging library.
*/
interface Logger {
fun debug(
message: String,
throwable: Throwable? = null,
)
fun info(
message: String,
throwable: Throwable? = null,
)
fun warning(
message: String,
throwable: Throwable? = null,
)
fun error(
message: String,
throwable: Throwable? = null,
)
}