Skip to main content

Welcome to the Tofu Logging Home page

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

Installation

Add these dependencies into your project:

libraryDependencies += "tf.tofu" %% "tofu-logging" % "<latest version in the badge in README>"
libraryDependencies += "tf.tofu" %% "tofu-logging-derivation" % "<latest version in the badge in README>"

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:

libraryDependencies += "tf.tofu" %% "tofu-core-ce3" % "<latest version in the badge in README>"

and Cats Effect 2 users should add:

libraryDependencies += "tf.tofu" %% "tofu-core-ce2" % "<latest version in the badge in README>"

For ZIO users the following is enough:

libraryDependencies += "tf.tofu" %% "tofu-zio2-logging" % "<latest version in the badge in README>" // OR:
libraryDependencies += "tf.tofu" %% "tofu-zio-logging" % "<latest version in the badge in README>"

See also ZIO1, ZIO2 Logging sections.

Quick demo

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

What's next

Old documentation

You can also visit obsolete documentation here.