ktor icon indicating copy to clipboard operation
ktor copied to clipboard

Ktor-client-logging : Add an option to filter logged calls

Open eMZet-zz opened this issue 4 years ago • 4 comments

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.

eMZet-zz avatar Feb 06 '20 08:02 eMZet-zz

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] avatar May 07 '20 12:05 stale[bot]

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

oleg-larshin avatar Aug 10 '20 15:08 oleg-larshin

Hey I would like to try to solve this one

AndresAusecha avatar Dec 05 '21 00:12 AndresAusecha

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)
        }
    }

mervyn-mccreight avatar May 01 '22 14:05 mervyn-mccreight

Fixed by https://github.com/ktorio/ktor/commit/da7cb98d829596fe66342e47e5a5f270e63c261c

Stexxe avatar Nov 28 '22 12:11 Stexxe