Skip to content

Commit

Permalink
chore: Do not log warn message for 405 and 404 status code responses (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Sep 29, 2023
1 parent dde3365 commit d9fd81c
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand All @@ -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)
}
}

0 comments on commit d9fd81c

Please sign in to comment.