Other question: On CallLoging plugin I’m filtering...
# ktor
a
Other question: On CallLoging plugin I’m filtering
Copy code
call.request.path().startsWith("/subscriptions")
but it is logging /health also, so it seems it is logging all Thanks!
a
Can you share the complete CallLogging plugin configuration?
a
Copy code
install(CallLogging) {
    level = <http://Level.INFO|Level.INFO>
    filter { call -> call.request.path().startsWith("/subscriptions") }
    format { call ->
        runBlocking {
            val headersSet: MutableMap<String, String> = mutableMapOf()
            call.request.headers.forEach { key, values ->
                values.forEach { value ->
                    headersSet[key] = value
                }
            }

            val headersString = headersSet.map { (key, value) -> "$key, $value" }.joinToString("-")

            "Body: ${call.receiveText()} - Headers: $headersString"
        }
    }
}
Maybe there is a better way to print headers
a
Unfortunately, I cannot reproduce your problem with the following code:
Copy code
embeddedServer(Netty, port = 4444) {
    install(CallLogging) {
        level = <http://Level.INFO|Level.INFO>
        filter { call -> call.request.path().startsWith("/subscriptions") }
    }
    routing {
        get("/subscriptions") {
            call.respondText { "subscriptions" }
        }

        get("/health") {
            call.respondText { "health" }
        }
    }
}.start(wait = true)
a
I will try simple scenari. Thanks!
Sorry, this is working well
I thought requests trace logs were coming by default by this filter also
This filter is filtering request to log whats inside the format (ex. “Headers”), right?
Is there a way to filter also tracing requests?
a
There are no such filters. The logger provider may support a similar filtering.
a
Thanks