From 56b4b6bec787f3eec0682d8f64af2df75383ef3f Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Wed, 23 Jun 2021 11:40:35 -0500 Subject: [PATCH] add instance for Logger[Kleisli[F, A, *]] --- .../src/main/scala/org/typelevel/log4cats/Logger.scala | 5 ++++- .../extras/syntax/LoggerSyntaxCompilation.scala | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/shared/src/main/scala/org/typelevel/log4cats/Logger.scala b/core/shared/src/main/scala/org/typelevel/log4cats/Logger.scala index a3a63a34..28410bf2 100644 --- a/core/shared/src/main/scala/org/typelevel/log4cats/Logger.scala +++ b/core/shared/src/main/scala/org/typelevel/log4cats/Logger.scala @@ -17,7 +17,7 @@ package org.typelevel.log4cats import cats._ -import cats.data.{EitherT, OptionT} +import cats.data.{EitherT, Kleisli, OptionT} trait Logger[F[_]] extends MessageLogger[F] with ErrorLogger[F] { def withModifiedString(f: String => String): Logger[F] = Logger.withModifiedString[F](this, f) @@ -33,6 +33,9 @@ object Logger { implicit def eitherTLogger[F[_]: Logger: Functor, E]: Logger[EitherT[F, E, *]] = Logger[F].mapK(EitherT.liftK[F, E]) + implicit def kleisliLogger[F[_]: Logger, A]: Logger[Kleisli[F, A, *]] = + Logger[F].mapK(Kleisli.liftK[F, A]) + private def withModifiedString[F[_]](l: Logger[F], f: String => String): Logger[F] = new Logger[F] { def error(message: => String): F[Unit] = l.error(f(message)) diff --git a/core/shared/src/test/scala/org/typelevel/log4cats/extras/syntax/LoggerSyntaxCompilation.scala b/core/shared/src/test/scala/org/typelevel/log4cats/extras/syntax/LoggerSyntaxCompilation.scala index 23090c8b..947df373 100644 --- a/core/shared/src/test/scala/org/typelevel/log4cats/extras/syntax/LoggerSyntaxCompilation.scala +++ b/core/shared/src/test/scala/org/typelevel/log4cats/extras/syntax/LoggerSyntaxCompilation.scala @@ -17,6 +17,7 @@ package org.typelevel.log4cats.extras.syntax import cats._ +import cats.data.{EitherT, Kleisli, OptionT} import org.typelevel.log4cats._ object LoggerSyntaxCompilation { @@ -52,4 +53,13 @@ object LoggerSyntaxCompilation { ): SelfAwareStructuredLogger[F] = l.withModifiedString(identity) + def eitherTLogger[F[_]: Functor: Logger, A]: EitherT[F, A, Unit] = + Logger[EitherT[F, A, *]].info("foo") + + def kleisliLogger[F[_]: Logger, A]: Kleisli[F, A, Unit] = + Logger[Kleisli[F, A, *]].info("bar") + + def optionTLogger[F[_]: Functor: Logger]: OptionT[F, Unit] = + Logger[OptionT[F, *]].info("baz") + }