by ChristopherDavenport

ChristopherDavenport / log4cats

Logging Tools For Interaction with cats-effect

221 Stars 31 Forks Last release: 6 months ago (v1.1.1) Apache License 2.0 601 Commits 25 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

log4cats Build Status Maven Central

Project Goals

log4cats attempts to make referentially transparent logging a reality. These F algebras allow you to write code for logging knowing you won't be doing side-effects as it offers no way to do so. We provide our own slf4j layer, or you can use any of the supported backends, or create your own.

Quick Start

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

libraryDependencies ++= Seq(
  "io.chrisdavenport" %% "log4cats-core"    % "",  // Only if you want to Support Any Backend
  "io.chrisdavenport" %% "log4cats-slf4j"   % "",  // Direct Slf4j Support - Recommended


import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.slf4j.Slf4jLogger
import cats.effect.Sync
import cats.implicits._

object MyThing { // Impure But What 90% of Folks I know do with log4s implicit def unsafeLogger[F[_]: Sync] = Slf4jLogger.getLogger[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.flatMap{ case Left(e) => Logger[F].error(e)("Something Went Wrong") case Right() => Sync[F].pure(()) }

def safelyDoThings[F[_]: Sync]: F[Unit] = for { logger logger.error(e)("Something Went Wrong in safelyDoThings")} _ Logger[F].error(e)("Something Went Wrong in passForEasierUse")} _

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.