Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions extensions/kermit-ktor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Kermit-Ktor Integration

The Kermit-Ktor module provides a way to add multiplatform logging to your Ktor client.

Firstly, add the gradle dependency to your project.

```kotlin
sourceSets {
commonMain {
dependencies {
implementation("co.touchlab:kermit-ktor:x.y.z") // Add the latest version
}
}
}
```

Then add the Kermit logger when you create your Ktor client -

```kotlin
val httpClient = HttpClient {
install(Logging) {
logger = KermitKtorLogger(severity = Severity.Info, logger = KermitLogger)
level = LogLevel.INFO
}
}
```

or alternatively

```kotlin
val httpClient = HttpClient {
install(Logging) {
logger = KermitKtorLogger(severity = Severity.Info, config = loggerConfigInit(CommonWriter()), tag = "")
level = LogLevel.INFO
}
}
```
7 changes: 7 additions & 0 deletions extensions/kermit-ktor/api/kermit-ktor.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public final class co/touchlab/kermit/ktor/KermitKtorLogger : io/ktor/client/plugins/logging/Logger {
public fun <init> (Lco/touchlab/kermit/Severity;Lco/touchlab/kermit/Logger;)V
public fun <init> (Lco/touchlab/kermit/Severity;Lco/touchlab/kermit/LoggerConfig;Ljava/lang/String;)V
public synthetic fun <init> (Lco/touchlab/kermit/Severity;Lco/touchlab/kermit/LoggerConfig;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun log (Ljava/lang/String;)V
}

62 changes: 62 additions & 0 deletions extensions/kermit-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2025 Touchlab
* 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(libs.plugins.android.library)
alias(libs.plugins.kotlin.multiplatform)
id("kermit-jvm-target")
id("wasm-setup")
id("kermit-publish")
}

kotlin {
androidTarget {
publishLibraryVariants()
}
macosX64()
macosArm64()
iosX64()
iosArm64()
iosSimulatorArm64()
tvosArm64()
tvosSimulatorArm64()
tvosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosDeviceArm64()
watchosX64()
js {
browser()
nodejs()
}

sourceSets {
commonMain.dependencies {
implementation(libs.ktor.logging)
implementation(project(":kermit"))
}
}
}

android {
namespace = "co.touchlab.kermit.ktor"
compileSdk = libs.versions.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2025 Touchlab
* 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 co.touchlab.kermit.ktor

import co.touchlab.kermit.Logger as KermitLogger
import co.touchlab.kermit.LoggerConfig
import co.touchlab.kermit.Severity
import io.ktor.client.plugins.logging.Logger as KtorLogger

class KermitKtorLogger(private val severity: Severity, private val logger: KermitLogger) : KtorLogger {

constructor(
severity: Severity,
config: LoggerConfig,
tag: String = "",
) : this(
logger = KermitLogger(config = config, tag = tag),
severity = severity,
)

override fun log(message: String) {
logger.log(severity, logger.tag, null, message)
}
}
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ koin = "4.1.0"
coroutines = "1.7.3"
kotlinx-datetime = "0.7.0"
kotlinx-io = "0.8.0"
kotlinx-js = "0.12.0"
kotlinx-wasm = "0.3.1"
roboelectric = "4.10.3"
buildConfig = "5.6.7"
mavenPublish = "0.34.0"
Expand All @@ -36,6 +38,7 @@ android-junitTest = "1.1.5"
junit = "4.13.2"
dokka = "2.0.0"
touchlab-docusaurus-template = "0.1.11"
ktor = "3.2.3"

ktlint-gradle = "12.3.0"

Expand All @@ -52,13 +55,18 @@ androidx-runner = { module = "androidx.test:runner", version.ref = "android-test
crashkios-crashlytics = { module = "co.touchlab.crashkios:crashlytics", version.ref = "crashkios" }
crashkios-bugsnag = { module = "co.touchlab.crashkios:bugsnag", version.ref = "crashkios" }
bugsnag-android = { module = "com.bugsnag:bugsnag-android", version.ref = "bugsnag" }
ktor-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
stately-collections = { module = "co.touchlab:stately-collections", version.ref = "stately" }
testhelp = { module = "co.touchlab:testhelp", version.ref = "testhelp" }

koin = { module = "io.insert-koin:koin-core", version.ref = "koin" }
coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
kotlinx-js = { module = "org.jetbrains.kotlinx:kotlinx-html-js", version.ref = "kotlinx-js" }
kotlinx-wasm = { module = "org.jetbrains.kotlinx:kotlinx-browser-wasm-js", version.ref = "kotlinx-wasm"}
roboelectric = { module = "org.robolectric:robolectric", version.ref = "roboelectric" }

coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
Expand Down
120 changes: 119 additions & 1 deletion kotlin-js-store/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading