diff --git a/log4cats/src/test/resources/logback-test.xml b/log4cats/src/test/resources/logback-test.xml new file mode 100644 index 000000000..284e7a753 --- /dev/null +++ b/log4cats/src/test/resources/logback-test.xml @@ -0,0 +1,11 @@ + + + + %date | log_level=%-5level '%msg'%n + + + + + + + diff --git a/log4cats/src/test/scalajvm/com/dwolla/util/tagless/logging/Example.scala b/log4cats/src/test/scalajvm/com/dwolla/util/tagless/logging/Example.scala new file mode 100644 index 000000000..87a0743d8 --- /dev/null +++ b/log4cats/src/test/scalajvm/com/dwolla/util/tagless/logging/Example.scala @@ -0,0 +1,35 @@ +package test + +import cats.* +import cats.effect.* +import cats.tagless.* +import cats.tagless.aop.* +import com.dwolla.util.tagless.logging.* +import org.typelevel.log4cats.slf4j.Slf4jFactory + +trait MyAlgebra[F[_]] { + def foo(foo: Int, bar: String): F[Boolean] +} + +object MyAlgebra { + implicit val showInt: Show[Int] = Show.fromToString + implicit val showString: Show[String] = Show.show[String](identity) + implicit val showBoolean: Show[Boolean] = Show.fromToString + + implicit val loggingMyAlgebraAspect: Aspect[MyAlgebra, Show, Show] = Derive.aspect +} + +object MyApp extends IOApp.Simple { + private val fakeMyAlgebra: MyAlgebra[IO] = new MyAlgebra[IO] { + override def foo(foo: Int, bar: String): IO[Boolean] = + IO.pure(true) + } + + override def run: IO[Unit] = + Slf4jFactory.create[IO].create.flatMap { implicit logger => + fakeMyAlgebra + .withMethodLogging + .foo(42, "The Answer to the Ultimate Question of Life, the Universe, and Everything") + .flatMap(IO.println) + } +} diff --git a/project/AsyncUtilsBuildPlugin.scala b/project/AsyncUtilsBuildPlugin.scala index 42a23e914..dd9da5c79 100644 --- a/project/AsyncUtilsBuildPlugin.scala +++ b/project/AsyncUtilsBuildPlugin.scala @@ -228,7 +228,12 @@ object AsyncUtilsBuildPlugin extends AutoPlugin { }, tlVersionIntroduced := Map("2.12" -> "1.2.0", "2.13" -> "1.2.0"), ) - .jvmPlatform(Scala2Versions) + .jvmPlatform(Scala2Versions, Seq( + libraryDependencies ++= Seq( + "org.typelevel" %%% "log4cats-slf4j" % "2.6.0" % Test, + "ch.qos.logback" % "logback-classic" % "1.4.5" % Test, + ), + )) .jsPlatform(Scala2Versions) private lazy val `scalafix-rules` =