-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example of how to use log4cats module
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%date | log_level=%-5level '%msg'%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
35 changes: 35 additions & 0 deletions
35
log4cats/src/test/scalajvm/com/dwolla/util/tagless/logging/Example.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters