Skip to content

Cats Effect Support

Matt Hicks edited this page Feb 6, 2022 · 1 revision

SBT Dependency

libraryDependencies += "com.outr" %% "scribe-cats" % scribeVersion

Uses

There are many ways you can leverage the cats module for Scribe. It is intentionally very flexible to allow for many use-cases. The goal of this module is to abstract the side-effects of Scribe into a F[_] return.

Simple IO use-case

The simplest scenario is to use the convenience reference to leverage the IO type:

scribe.cats.io.info("Hello, World!") // Returns IO[Unit]

Ad-hoc F[_] type

For greater flexibility, you can do ad-hoc calls to use an arbitrary type. For the purposes of this example, we'll just use IO:

scribe.cats[IO].info("Hello, World!") // Returns IO[Unit]

You can also create the reference ahead of time to avoid requiring the implicit Sync[F] during calls:

val logger = scribe.cats[IO]

logger.info("Hello, World!") // Returns IO[Unit]

Using an Existing Logger

If you are mixing uses or have a more specific controlled scenario you want to handle, you take a Logger instance and use it through the cats module:

import scribe.cats._

val logger = Logger("MyLogger")
logger.f[IO].info("Hello, World!") // Returns IO[Unit]

Instantiated Logging

A much more complex scenario:

class Biz[F[_]: MonadThrow: Scribe] {
  def doStuff(): F[String] = for {
    _ <- Scribe[F].info("Hello, World!") // Returns IO[Unit]
  } yield {
    "done"
  }
}

val biz = new Biz[IO]
biz.doStuff()
Clone this wiki locally