Skip to content

Commit

Permalink
Make a more meaty example of the syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
danicheg committed Dec 28, 2021
1 parent cb870a0 commit 4673c28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ It's possible to use interpolated syntax for logging.
Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`.
You can use it for your custom `Logger` as well as for Slf4j `Logger`.

```scala mdoc
```scala
import cats.Applicative
import cats.effect.Sync
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.syntax._

def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1)
def successComputation[F[_]: Applicative]: F[Int] = Applicative[F].pure(1)
def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!"))

def log[F[_]: Sync: Logger] =
Expand Down
7 changes: 5 additions & 2 deletions docs/src/main/mdoc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`.
You can use it for your custom `Logger` as well as for Slf4j `Logger`.

```scala mdoc
import cats.Applicative
import cats.effect.Sync
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.syntax._

def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1)
def successComputation[F[_]: Applicative]: F[Int] = Applicative[F].pure(1)
def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!"))

def log[F[_]: Sync: Logger] =
for {
result1 <- successComputation[F]
_ <- info"First result is $result1"
_ <- errorComputation[F].onError(_ => error"We got an error!")
_ <- errorComputation[F].onError {
case _ => error"We got an error!"
}
} yield ()
```

0 comments on commit 4673c28

Please sign in to comment.