diff --git a/src/main/resources/logback-http.xml b/src/main/resources/logback-http.xml index d8d39dd..47ac39e 100644 --- a/src/main/resources/logback-http.xml +++ b/src/main/resources/logback-http.xml @@ -2,7 +2,7 @@ - [%d{yyyy-MM-dd HH:mm:ss.SSS}] %marker %msg%n + %msg%n http.log diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 722a79e..2cfefec 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -8,6 +8,9 @@ + + + diff --git a/src/main/scala/me/arcanis/ffxivbis/http/RootEndpoint.scala b/src/main/scala/me/arcanis/ffxivbis/http/RootEndpoint.scala index 75962e1..23e9e55 100644 --- a/src/main/scala/me/arcanis/ffxivbis/http/RootEndpoint.scala +++ b/src/main/scala/me/arcanis/ffxivbis/http/RootEndpoint.scala @@ -8,11 +8,13 @@ */ package me.arcanis.ffxivbis.http +import java.time.Instant + import akka.actor.{ActorRef, ActorSystem} import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server._ import akka.util.Timeout -import com.typesafe.scalalogging.StrictLogging +import com.typesafe.scalalogging.{Logger, StrictLogging} import me.arcanis.ffxivbis.http.api.v1.RootApiV1Endpoint import me.arcanis.ffxivbis.http.view.RootView @@ -27,8 +29,22 @@ class RootEndpoint(system: ActorSystem, storage: ActorRef, ariyala: ActorRef) private val rootApiV1Endpoint: RootApiV1Endpoint = new RootApiV1Endpoint(storage, ariyala) private val rootView: RootView = new RootView(storage, ariyala) + private val httpLogger = Logger("http") - def route: Route = apiRoute ~ htmlRoute ~ Swagger.routes ~ swaggerUIRoute + private val withHttpLog: Directive0 = + extractRequestContext.flatMap { context => + val start = Instant.now.toEpochMilli + mapResponse { response => + val time = (Instant.now.toEpochMilli - start) / 1000.0 + httpLogger.debug(s"""- - [${Instant.now}] "${context.request.method.name()} ${context.request.uri.path}" ${response.status.intValue()} ${response.entity.getContentLengthOption.getAsLong} $time""") + response + } + } + + def route: Route = + withHttpLog { + apiRoute ~ htmlRoute ~ Swagger.routes ~ swaggerUIRoute + } private def apiRoute: Route = ignoreTrailingSlash {