jozefdransfield
06/19/2018, 9:03 PMDeactivated User
06/20/2018, 5:23 AMtoString
method that you can use, or to help you see how to build your own string based on the tree:
https://github.com/ktorio/ktor/blob/0a45746af0db0457a6e1e988c27d9364cf064962/ktor-server/ktor-server-core/src/io/ktor/routing/Route.kt#L98
An interceptor for a route would look like this:
https://ktor.io/advanced/pipeline/route.html
There you have access to the Route node treeDeactivated User
06/20/2018, 12:22 PMRoutingApolicationCall
I have updated the doc to reflect this: https://ktor.io/advanced/pipeline/route.html#route-from-callvonox7
06/21/2018, 1:09 PMjava.lang.ClassCastException: io.ktor.server.jetty.JettyApplicationCall cannot be cast to io.ktor.routing.RoutingApplicationCall: Ljava/lang/ClassCastException;
Deactivated User
06/21/2018, 1:10 PMvonox7
06/21/2018, 1:17 PMnull
, as the cast wonāt succeedvonox7
06/21/2018, 1:20 PMembeddedServer(Netty, ...)
Deactivated User
06/21/2018, 1:20 PMDeactivated User
06/21/2018, 1:21 PMDeactivated User
06/21/2018, 1:23 PMDeactivated User
06/21/2018, 1:27 PMenvironment.monitor.subscribe(Routing.RoutingCallFinished) {
println(it.route)
}
Deactivated User
06/21/2018, 1:27 PMDeactivated User
06/21/2018, 1:28 PMvonox7
06/21/2018, 1:30 PMDeactivated User
06/21/2018, 1:31 PMDeactivated User
06/21/2018, 1:31 PMDeactivated User
06/21/2018, 1:31 PMvonox7
06/21/2018, 1:31 PMvonox7
06/21/2018, 1:33 PMDeactivated User
06/21/2018, 1:34 PMfun Application.registerMyRouteLogging() {
fun log(path: String, handled: Boolean) {
println("path=$path, handled=$handled")
}
environment.monitor.subscribe(Routing.RoutingCallFinished) { routingApplicationCall ->
log(routingApplicationCall.route.toString(), handled = true)
}
intercept(ApplicationCallPipeline.Fallback) {
log(call.request.uri, handled = false)
}
}
vonox7
06/21/2018, 1:36 PMDeactivated User
06/21/2018, 1:36 PMDeactivated User
06/21/2018, 1:39 PMval StartTimeAttribute = AttributeKey<Long>("StartTimeAttribute")
fun Application.registerMyRouteLogging() {
fun log(call: ApplicationCall, path: String, handled: Boolean) {
val elapsedTime = System.currentTimeMillis() - call.attributes[StartTimeAttribute]
println("path=$path, handled=$handled, elapsedTime=$elapsedTime")
}
intercept(ApplicationCallPipeline.Infrastructure) {
call.attributes.put(StartTimeAttribute, System.currentTimeMillis())
}
environment.monitor.subscribe(Routing.RoutingCallFinished) { call ->
log(call, call.route.toString(), handled = true)
}
intercept(ApplicationCallPipeline.Fallback) {
log(call, call.request.uri, handled = false)
}
}
Deactivated User
06/21/2018, 1:41 PMDeactivated User
06/21/2018, 1:42 PMDeactivated User
06/21/2018, 1:42 PMDeactivated User
06/21/2018, 1:42 PMvonox7
06/21/2018, 1:47 PMpath=/route/one/(method:GET), handled=true, elapsedTime=84
path=/route/one, handled=false, elapsedTime=84
Deactivated User
06/21/2018, 1:49 PMDeactivated User
06/21/2018, 1:49 PMDeactivated User
06/21/2018, 1:49 PMDeactivated User
06/21/2018, 1:50 PMvonox7
06/21/2018, 1:58 PMDeactivated User
06/21/2018, 1:59 PMDeactivated User
06/21/2018, 1:59 PMDeactivated User
06/21/2018, 1:59 PMvonox7
06/21/2018, 2:00 PMvonox7
06/21/2018, 2:04 PMDeactivated User
06/21/2018, 2:04 PMDeactivated User
06/21/2018, 2:04 PMvonox7
06/21/2018, 2:04 PM