Skip to content
Purely functional logging using cats-effect and cats-mtl
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore
.travis.yml
README.md
build.sbt
rings.tar.enc
version.sbt

README.md

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()
You can’t perform that action at this time.