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

Remove log4s usage in http4s-server integration #3663

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
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 @@ -12,7 +12,8 @@ import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.server.middleware._
import org.http4s.server.websocket.WebSocketBuilder2
import org.http4s.websocket.WebSocketFrame
import org.http4s.{multipart, _}
import org.http4s._
import org.slf4j.LoggerFactory
import org.typelevel.ci.CIString
import scodec.bits.ByteVector
import sttp.tapir.client.tests.HttpServer._
Expand All @@ -30,7 +31,7 @@ object HttpServer {

class HttpServer(port: Port) {

private val logger = org.log4s.getLogger
private val logger = LoggerFactory.getLogger(getClass)

private var stopServer: IO[Unit] = _

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package sttp.tapir.server.http4s

import cats.effect.Sync
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
import sttp.tapir.server.interceptor.log.DefaultServerLog
import org.log4s.{Logger, getLogger}

object Http4sDefaultServerLog {
private[http4s] val log: Logger = getLogger

def apply[F[_]: Sync]: DefaultServerLog[F] = {
val log = Slf4jLogger.getLogger[F]
DefaultServerLog(
doLogWhenReceived = debugLog(_, None),
doLogWhenHandled = debugLog[F],
doLogAllDecodeFailures = debugLog[F],
doLogExceptions = (msg: String, ex: Throwable) => Sync[F].delay(log.error(ex)(msg)),
doLogWhenReceived = msg => debugLog(log)(msg, None),
doLogWhenHandled = debugLog(log),
doLogAllDecodeFailures = debugLog(log),
doLogExceptions = (msg: String, ex: Throwable) => log.error(ex)(msg),
noLog = Sync[F].pure(())
)
}

private def debugLog[F[_]](msg: String, exOpt: Option[Throwable])(implicit sync: Sync[F]): F[Unit] =
private def debugLog[F[_]](log: Logger[F])(msg: String, exOpt: Option[Throwable]): F[Unit] =
exOpt match {
case None => Sync[F].delay(log.debug(msg))
case Some(ex) => Sync[F].delay(log.debug(ex)(msg))
case None => log.debug(msg)
case Some(ex) => log.debug(ex)(msg)
}
}
Loading