Turned out the problem is in rather akward design of ktor api. Summary of my findings:
Contrary to common expectation to see log events of specified log level and above it doesn't that way with CallLogging
. It expects exact match of the logging level which minimizes usefulness of this feature.
You need to overwrite logger specified in ApplicationEnvironment.log
. But if you follow official ktor examples and do it like this
val server = embeddedServer(Netty, port) {
applicationEngineEnvironment {
log = YOUR_LOGGER
}
}
it won't work because value call.application.environment
inside function io.ktor.server.engine.defaultEnginePipeline(env)
is still original one, created from logger name in config file or NOP logger.
Hence you'll need to initialize your server like this
val env = applicationEngineEnvironment {
log = YOUR_LOGGER
module {
install(CallLogging) {
level = org.slf4j.event.Level.INFO
}
install(StatusPages) {
exception<Throwable> { ex ->
val callstack: String = ...
call.respond(HttpStatusCode.InternalServerError,
ApiError(ex.javaClass.simpleName, ex.message ?: "Empty Message", callstack)
)
throw ex
}
}
routing {
}
}
connector {
host = "0.0.0.0"
port = ...
}
}
val server = embeddedServer(Netty, env)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…