增强日志

This commit is contained in:
tursom 2019-12-15 00:31:59 +08:00
parent e41da3463a
commit e4c6b5657e
3 changed files with 13 additions and 8 deletions

View File

@ -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) + " " +

View File

@ -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)?) {

View File

@ -24,6 +24,7 @@ open class AsyncRoutedHttpHandler(
protected val asyncRouterMap: HashMap<String, Router<Pair<Any?, suspend (HttpContent) -> 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
}