ktor
ktor copied to clipboard
Ktor-client-logging : Add an option to filter logged calls
Subsystem Kotlin multiplatform library: ktor-client-logging:1.3.0
Is your feature request related to a problem? Please describe. Problem: not able to filter calls to be logged. All calls are being logged by default.
Describe the solution you'd like Add a filter option in Logging configuration block (this solution is available on Android in CallLogging feature, but it is absent in kotlin multiplatform) https://ktor.io/servers/features/call-logging.html
install(Logging) {
filter { call -> call.request.path().startsWith("/section1") }
}
Motivation to include to ktor Logging all queries is helpful in debug mode. However, for a production version in which, for example, logs are saved to a file, saving only failed requests would be sufficient. It would be convenient to use the function that is already in the library.
This issue has been automatically marked as stale because it has not had recent activity.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Hey I would like to try to solve this one
Is this really still open?
Looking at ktor-client/ktor-client-plugins/ktor-client-logging/common/src/io/ktor/client/plugins/logging/Logging.kt
it looks like this is there already:
/**
* [Logging] plugin configuration
*/
@KtorDsl
public class Config {
/**
* filters
*/
internal var filters = mutableListOf<(HttpRequestBuilder) -> Boolean>()
/**
* [Logger] instance to use
*/
public var logger: Logger = Logger.DEFAULT
/**
* log [LogLevel]
*/
public var level: LogLevel = LogLevel.HEADERS
/**
* Log messages for calls matching a [predicate].
*/
public fun filter(predicate: (HttpRequestBuilder) -> Boolean) {
filters.add(predicate)
}
}
Fixed by https://github.com/ktorio/ktor/commit/da7cb98d829596fe66342e47e5a5f270e63c261c