mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Adopt to new loggin api
This commit is contained in:
@ -22,7 +22,6 @@ import org.http4s.client.middleware.RequestLogger
|
||||
import org.http4s.client.middleware.ResponseLogger
|
||||
import org.http4s.headers.Accept
|
||||
import org.http4s.headers.Authorization
|
||||
import org.log4s.getLogger
|
||||
|
||||
/** https://openid.net/specs/openid-connect-core-1_0.html (OIDC)
|
||||
* https://openid.net/specs/openid-connect-basic-1_0.html#TokenRequest (OIDC)
|
||||
@ -30,7 +29,6 @@ import org.log4s.getLogger
|
||||
* https://datatracker.ietf.org/doc/html/rfc7519 (JWT)
|
||||
*/
|
||||
object CodeFlow {
|
||||
private[this] val log4sLogger = getLogger
|
||||
|
||||
def apply[F[_]: Async, A](
|
||||
client: Client[F],
|
||||
@ -39,7 +37,7 @@ object CodeFlow {
|
||||
)(
|
||||
code: String
|
||||
): OptionT[F, Json] = {
|
||||
val logger = Logger.log4s[F](log4sLogger)
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
val dsl = new Http4sClientDsl[F] {}
|
||||
val c = logRequests[F](logResponses[F](client))
|
||||
|
||||
@ -93,7 +91,7 @@ object CodeFlow {
|
||||
code: String
|
||||
): OptionT[F, AccessToken] = {
|
||||
import dsl._
|
||||
val logger = Logger.log4s[F](log4sLogger)
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
|
||||
val req = POST(
|
||||
UrlForm(
|
||||
@ -133,7 +131,7 @@ object CodeFlow {
|
||||
token: AccessToken
|
||||
): OptionT[F, Json] = {
|
||||
import dsl._
|
||||
val logger = Logger.log4s[F](log4sLogger)
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
|
||||
val req = GET(
|
||||
Uri.unsafeFromString(endpointUrl.asString),
|
||||
@ -162,18 +160,22 @@ object CodeFlow {
|
||||
OptionT(resp)
|
||||
}
|
||||
|
||||
private def logRequests[F[_]: Async](c: Client[F]): Client[F] =
|
||||
private def logRequests[F[_]: Async](c: Client[F]): Client[F] = {
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
RequestLogger(
|
||||
logHeaders = true,
|
||||
logBody = true,
|
||||
logAction = Some((msg: String) => Logger.log4s(log4sLogger).trace(msg))
|
||||
logAction = Some((msg: String) => logger.trace(msg))
|
||||
)(c)
|
||||
}
|
||||
|
||||
private def logResponses[F[_]: Async](c: Client[F]): Client[F] =
|
||||
private def logResponses[F[_]: Async](c: Client[F]): Client[F] = {
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
ResponseLogger(
|
||||
logHeaders = true,
|
||||
logBody = true,
|
||||
logAction = Some((msg: String) => Logger.log4s(log4sLogger).trace(msg))
|
||||
logAction = Some((msg: String) => logger.trace(msg))
|
||||
)(c)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,10 +17,8 @@ import org.http4s._
|
||||
import org.http4s.client.Client
|
||||
import org.http4s.dsl.Http4sDsl
|
||||
import org.http4s.headers.Location
|
||||
import org.log4s.getLogger
|
||||
|
||||
object CodeFlowRoutes {
|
||||
private[this] val log4sLogger = getLogger
|
||||
|
||||
def apply[F[_]: Async](
|
||||
enabled: Boolean,
|
||||
@ -38,7 +36,7 @@ object CodeFlowRoutes {
|
||||
): HttpRoutes[F] = {
|
||||
val dsl: Http4sDsl[F] = new Http4sDsl[F] {}
|
||||
import dsl._
|
||||
val logger = Logger.log4s[F](log4sLogger)
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
HttpRoutes.of[F] {
|
||||
case req @ GET -> Root / Ident(id) =>
|
||||
config.findProvider(id) match {
|
||||
|
@ -10,13 +10,10 @@ import cats.effect._
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.common.Logger
|
||||
|
||||
import io.circe.Json
|
||||
import org.http4s._
|
||||
import org.http4s.headers.`Content-Type`
|
||||
import org.http4s.implicits._
|
||||
import org.log4s.getLogger
|
||||
|
||||
/** Once the authentication flow is completed, we get "some" json structure that contains
|
||||
* a claim about the user. From here it's to the user of this small library to complete
|
||||
@ -44,18 +41,16 @@ trait OnUserInfo[F[_]] {
|
||||
}
|
||||
|
||||
object OnUserInfo {
|
||||
private[this] val log = getLogger
|
||||
|
||||
def apply[F[_]](
|
||||
f: (Request[F], ProviderConfig, Option[Json]) => F[Response[F]]
|
||||
): OnUserInfo[F] =
|
||||
(req: Request[F], cfg: ProviderConfig, userInfo: Option[Json]) =>
|
||||
f(req, cfg, userInfo)
|
||||
|
||||
def logInfo[F[_]: Sync]: OnUserInfo[F] =
|
||||
def logInfo[F[_]: Sync]: OnUserInfo[F] = {
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
OnUserInfo((_, _, json) =>
|
||||
Logger
|
||||
.log4s(log)
|
||||
logger
|
||||
.info(s"Got data: ${json.map(_.spaces2)}")
|
||||
.map(_ =>
|
||||
Response[F](Status.Ok)
|
||||
@ -65,4 +60,5 @@ object OnUserInfo {
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user