From e4c6b5657e5acda6173c8d85e47af5650471d31e Mon Sep 17 00:00:00 2001 From: tursom Date: Sun, 15 Dec 2019 00:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log/src/main/kotlin/cn/tursom/log/Slf4jEnhance.kt | 2 +- .../kotlin/cn/tursom/web/router/RoutedHttpHandler.kt | 11 +++++++---- .../cn/tursom/web/router/AsyncRoutedHttpHandler.kt | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/log/src/main/kotlin/cn/tursom/log/Slf4jEnhance.kt b/log/src/main/kotlin/cn/tursom/log/Slf4jEnhance.kt index da96e87..40fde06 100644 --- a/log/src/main/kotlin/cn/tursom/log/Slf4jEnhance.kt +++ b/log/src/main/kotlin/cn/tursom/log/Slf4jEnhance.kt @@ -61,7 +61,7 @@ fun configureLogbackDirectly(logDir: String, filePrefix: String) { val defaultColorfulPattern = LogbackPattern.make { +color { green }(+date)["yyyy-MM-dd HH:mm:ss.SSS"] + " " + - +color { magenta }("[${+thread}]") + " " + + +color { magenta }("[${+thread.right(15, 15)}]") + " " + +color { highlight }(+level.left(5)) + " " + +color { cyan }("[${+logger["20"].right(20, 20)}]") + " - " + +color { highlight }(+message) + " " + diff --git a/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt b/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt index 7bad839..2796a85 100644 --- a/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt +++ b/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt @@ -38,10 +38,13 @@ open class RoutedHttpHandler( addRouter(target ?: this) } - override fun handle(content: HttpContent) = if (content is MutableHttpContent) { - handle(content, getHandler(content, content.method, content.uri)) - } else { - handle(content, getHandler(content.method, content.uri).first?.second) + override fun handle(content: HttpContent) { + log?.debug("{}: {} {}", content.clientIp, content.method, content.uri) + if (content is MutableHttpContent) { + handle(content, getHandler(content, content.method, content.uri)) + } else { + handle(content, getHandler(content.method, content.uri).first?.second) + } } open fun handle(content: HttpContent, handler: ((HttpContent) -> Unit)?) { diff --git a/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt b/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt index 332c01c..e659824 100644 --- a/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt +++ b/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt @@ -24,6 +24,7 @@ open class AsyncRoutedHttpHandler( protected val asyncRouterMap: HashMap Unit>>> = HashMap() override fun handle(content: HttpContent) { + log?.debug("{}: {} {}", content.clientIp, content.method, content.uri) if (content is MutableHttpContent) { val handler = getAsyncHandler(content, content.method, content.uri) if (handler != null) GlobalScope.launch { @@ -194,8 +195,9 @@ open class AsyncRoutedHttpHandler( } } val mapping = handler::class.java.getAnnotation(Mapping::class.java)?.route ?: arrayOf("") - member.annotations.forEach { annotation -> - val (routes, router) = getAsyncRoutes(annotation) ?: return@forEach + member.annotations.forEach route@{ annotation -> + val (routes, router) = + getAsyncRoutes(annotation) ?: return@route @Suppress("DuplicatedCode") routes.forEach { route -> if (mapping.isEmpty()) { @@ -220,7 +222,7 @@ open class AsyncRoutedHttpHandler( companion object { private val log = try { - LoggerFactory.getLogger(RoutedHttpHandler::class.java) + LoggerFactory.getLogger(AsyncRoutedHttpHandler::class.java) } catch (e: Throwable) { null }