theinnerlight / pure-log   0.3.0

GitHub

Purely functional logging using cats-effect and cats-mtl

Scala versions: 2.12 2.11

pure-log

Build Status Latest version

Simple logging in IO

libraryDependencies += "org.novelfs" %% "pure-log" % "[Latest version]"

Works in any Applicative with a LiftIO instance.

import org.novelfs.pure.log.Logger
import org.novelfs.pure.log.simple._
import cats.effect.IO

Logger.log[IO](LogLevel.Info)("Hello World!").unsafeRunSync()

MDC Logging

Works in any Monad with a LiftIO instance and an ApplicativeLocal instance where the environment that you intend to read from has a ToMdc instance.

import org.novelfs.pure.log.Logger
import org.novelfs.pure.log.mdc._
import cats.data.ReaderT
import cats.mtl.implicits._

case class Captain(firstName : String, lastName : String)

implicit val captainToMdc = new ToMdc[Captain] {
  override def toMdc(captain: Captain): Map[String, String] = Map("firstName" -> captain.firstName, "lastName" -> captain.lastName)
}

Logger.log[ReaderT[IO, Captain, ?]](LogLevel.Info)("Hello World!")
  .run(Captain("James", "Kirk"))
  .unsafeRunSync()