diff --git a/webapi/src/main/scala/org/knora/webapi/routing/AroundDirectives.scala b/webapi/src/main/scala/org/knora/webapi/routing/AroundDirectives.scala index 4b3e834812..a6149b6d62 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/AroundDirectives.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/AroundDirectives.scala @@ -6,9 +6,9 @@ package org.knora.webapi.routing import org.apache.pekko - +import org.apache.pekko.http.scaladsl.model.StatusCodes.{MethodNotAllowed, NotFound} +import org.apache.pekko.http.scaladsl.model.{HttpResponse, StatusCodes} import org.knora.webapi.instrumentation.InstrumentationSupport - import pekko.http.scaladsl.server.Directive0 import pekko.http.scaladsl.server.Directives._ @@ -25,8 +25,15 @@ trait AroundDirectives extends InstrumentationSupport { mapResponse { resp => val took = System.currentTimeMillis() - start val message = s"[${resp.status.intValue()}] ${ctx.request.method.name} ${ctx.request.uri} took: ${took}ms" - if (resp.status.isFailure()) metricsLogger.warn(message) else metricsLogger.debug(message) + if (shouldLogWarning(resp)) metricsLogger.warn(message) + else metricsLogger.debug(message) resp } } + + private val doNotLogStatusCodes = List(MethodNotAllowed, NotFound) + private def shouldLogWarning(resp: HttpResponse) = { + val status = resp.status + status.isFailure() && !doNotLogStatusCodes.contains(status) + } }