-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only log request/reponse when errors
Add config to show every requests
- Loading branch information
1 parent
b2d9eb0
commit 695aafa
Showing
5 changed files
with
39 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package lila.search | ||
package app | ||
|
||
import cats.data.Kleisli | ||
import cats.effect.IO | ||
import cats.syntax.all.* | ||
import org.http4s.internal.Logger as Http4sLogger | ||
import org.http4s.{ HttpApp, Request, Response } | ||
import org.typelevel.log4cats.Logger | ||
|
||
object ApiErrorLogger: | ||
|
||
def isResponseError(res: Response[IO]): Boolean = | ||
!res.status.isSuccess && res.status.code != 404 | ||
|
||
private def logError(req: Request[IO], res: Response[IO])(using Logger[IO]): IO[Unit] = | ||
Http4sLogger.logMessage(req)(true, true)(Logger[IO].warn) >> | ||
Http4sLogger.logMessage(res)(true, true)(Logger[IO].warn) | ||
|
||
def instance(using Logger[IO]): HttpApp[IO] => HttpApp[IO] = http => | ||
Kleisli: req => | ||
http(req).flatTap: res => | ||
logError(req, res).whenA(isResponseError(res)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters