keirlawson / log4cats

Logging Tools For Interaction with cats-effect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

log4cats Build Status Maven Central

Quick Start

To use log4cats in an existing SBT project with Scala 2.11 or a later version, add the following dependency to your build.sbt:

libraryDependencies ++= Seq(
  "io.chrisdavenport" %% "log4cats-core"    % "<version>",  // Only if you want to Support Any Backend
  "io.chrisdavenport" %% "log4cats-log4s"   % "<version>",  // For Log4s Support
  "io.chrisdavenport" %% "log4cats-scribe"  % "<version>",   // For Scribe Support
)

Examples

import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.Log4sLogger
import cats.effect.Sync
import cats.implicits._

object MyThing {
  // Impure But What 90% of Folks I know do with log4s
  implicit def localLogger[F[_]: Sync] = Log4sLogger.createLocal[F]

  // Arbitrary Local Function Declaration
  def doSomething[F[_]: Sync]: F[Unit] =
    Logger[F].info("Logging Start Something") *>
    Sync[F].delay(println("I could be doing anything"))
      .attempt.flatTap{
        case Left(e) => Logger[F].error(e)("Something Went Wrong")
        case Right(_) => Sync[F].pure(())
      }
}

About

Logging Tools For Interaction with cats-effect


Languages

Language:Scala 100.0%