-
Notifications
You must be signed in to change notification settings - Fork 45
Ktor Extension #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Ktor Extension #458
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b1d684c
Adding initial extension
KevinSchildhorn fb1a9f5
updating call and readme
KevinSchildhorn 5227521
updating API
KevinSchildhorn 4cfb2a6
Updating readme and website
KevinSchildhorn 0887c9b
Adding Ktor Logger to sample
KevinSchildhorn 89ed118
Update website/docs/extensions/KTOR.md
KevinSchildhorn aa30a29
Update build_mac.yml
KevinSchildhorn 9357b3d
Update build_mac.yml
KevinSchildhorn 8297cf4
Revert "Update build_mac.yml"
KevinSchildhorn 7c2c50c
Merge branch 'main' into ks/KtorExtension
KevinSchildhorn 1755062
Adding JS to ktor extension
KevinSchildhorn d22d46f
Update package-lock.json
KevinSchildhorn a233b41
Updating package and removing deprecated code
KevinSchildhorn f543b76
updating browser sample
KevinSchildhorn 113eb3a
Update build.gradle.kts
KevinSchildhorn 15fbe7b
fixing resolution issue
KevinSchildhorn c104869
tweaking some final changes
KevinSchildhorn 7bdf6d9
Update build.gradle.kts
KevinSchildhorn 1cc6791
Merge branch 'ks/UpdateWasmBrowserSample' into ks/KtorExtension
KevinSchildhorn 368a7b2
finalizing version issues
KevinSchildhorn bf88bfc
package lock
faogustavo 83709c9
Update extensions/kermit-ktor/src/commonMain/kotlin/co/touchlab/kermi…
KevinSchildhorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
extensions/kermit-ktor/src/commonMain/kotlin/co/touchlab/kermit/ktor/KermitKtorLogger.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.