Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Do not log warn message for 405 and 404 status code responses #2854

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}