Skip to content

Quickstart

This is a set of tools for logging. Configurable, concise, handy.

Add these dependencies into your project:

logging requires an instance of the Delay typeclass, which can be created by hand, or can be imported from an according package:

Cats Effect 3 users should add the following dependency:

"tf.tofu" %% "tofu-core-ce3" % "0.14.0"

and Cats Effect 2 users should add:

"tf.tofu" %% "tofu-core-ce2" % "0.14.0"

For ZIO users the following is enough:

"tf.tofu" %% "tofu-zio2-logging" % "0.14.0" // OR:
"tf.tofu" %% "tofu-zio-logging" % "0.14.0"

See also ZIO1, ZIO2 Logging sections.

import tofu.syntax.logging._
import tofu.logging.Logging
import derevo.derive
import tofu.logging.derivation.loggable
type CardNumber = String //could be a newtype
@derive(loggable)
case class Client(name: String, @hidden cardNumber: CardNumber, id: UUID)
def processPayment[F[_] : Monad : Logging](client: Client, amount: Long): F[Result] =
for {
_ <- info"Processing payment for $client"
_ <- warn"Amount $amount is lower than zero!".whenA(amount < 0)
result <- processData(client, amount, "USD")
.onError(errorCause"Got error on processing payment for $client"(_))
} yield result

You can also visit obsolete documentation here.