Skip to content

Commit

Permalink
HttpRouterMonitor print log once each request
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoii committed Oct 9, 2023
1 parent 11b202d commit 0a3e454
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.*
import io.ktor.server.request.*
import io.ktor.util.*
import net.mamoe.mirai.utils.MiraiLogger

val logger by lazy { MiraiLogger.Factory.create(HttpRouterMonitor::class, "MAH Access") }
private val monitor = AttributeKey<Unit>("HttpRouterMonitor")
private val logger by lazy { MiraiLogger.Factory.create(HttpRouterMonitor::class, "MAH Access") }

val HttpRouterMonitor = createApplicationPlugin("HttpRouterAccessMonitor") {
on(Monitor) { call ->
if (call.attributes.contains(monitor)) {
return@on
}
call.attributes.put(monitor, Unit)
call.logAccess()
}
}
Expand Down

0 comments on commit 0a3e454

Please sign in to comment.