Skip to content

Commit

Permalink
Merge pull request #460 from Dwolla/kleisli
Browse files Browse the repository at this point in the history
add instance for Logger[Kleisli[F, A, *]]
  • Loading branch information
ChristopherDavenport authored Jun 26, 2021
2 parents 53b77ec + 56b4b6b commit 8440a1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.typelevel.log4cats.extras.syntax

import cats._
import cats.data.{EitherT, Kleisli, OptionT}
import org.typelevel.log4cats._

object LoggerSyntaxCompilation {
Expand Down Expand Up @@ -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")

}

0 comments on commit 8440a1f

Please sign in to comment.