From 0a3e454a04209cf8f8795921b8259b99df4d8148 Mon Sep 17 00:00:00 2001 From: ryoii Date: Mon, 9 Oct 2023 17:34:02 +0800 Subject: [PATCH] HttpRouterMonitor print log once each request --- .../api/http/adapter/http/plugin/HttpRouterMonitor.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/http/plugin/HttpRouterMonitor.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/http/plugin/HttpRouterMonitor.kt index 21940a32..22eaf6d3 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/http/plugin/HttpRouterMonitor.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/http/plugin/HttpRouterMonitor.kt @@ -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("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() } }