mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-04-24 17:27:17 +00:00
simple http log
This commit is contained in:
parent
2ad3600da5
commit
e03f8987b0
@ -2,7 +2,7 @@
|
||||
|
||||
<appender name="http-base" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %marker %msg%n</pattern>
|
||||
<pattern>%msg%n</pattern>
|
||||
</encoder>
|
||||
|
||||
<file>http.log</file>
|
||||
|
@ -8,6 +8,9 @@
|
||||
</root>
|
||||
|
||||
<logger name="me.arcanis.ffxivbis" level="DEBUG" />
|
||||
<logger name="http" level="DEBUG">
|
||||
<appender-ref ref="http" />
|
||||
</logger>
|
||||
<logger name="slick.jdbc.JdbcBackend.statement" level="DEBUG" />
|
||||
|
||||
</configuration>
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user