log4cats-core


License

License

GroupId

GroupId

io.chrisdavenport
ArtifactId

ArtifactId

log4cats-core_2.12
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

log4cats-core
log4cats-core
Project URL

Project URL

https://github.com/ChristopherDavenport/log4cats
Project Organization

Project Organization

io.chrisdavenport
Source Code Management

Source Code Management

https://github.com/ChristopherDavenport/log4cats

Download log4cats-core_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.chrisdavenport/log4cats-core_2.12/ -->
<dependency>
    <groupId>io.chrisdavenport</groupId>
    <artifactId>log4cats-core_2.12</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.chrisdavenport/log4cats-core_2.12/
implementation 'io.chrisdavenport:log4cats-core_2.12:1.1.1'
// https://jarcasting.com/artifacts/io.chrisdavenport/log4cats-core_2.12/
implementation ("io.chrisdavenport:log4cats-core_2.12:1.1.1")
'io.chrisdavenport:log4cats-core_2.12:jar:1.1.1'
<dependency org="io.chrisdavenport" name="log4cats-core_2.12" rev="1.1.1">
  <artifact name="log4cats-core_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.chrisdavenport', module='log4cats-core_2.12', version='1.1.1')
)
libraryDependencies += "io.chrisdavenport" % "log4cats-core_2.12" % "1.1.1"
[io.chrisdavenport/log4cats-core_2.12 "1.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.11
org.typelevel : cats-core_2.12 jar 2.1.1

test (1)

Group / Artifact Type Version
org.specs2 : specs2-core_2.12 jar 4.9.4

Project Modules

There are no modules declared in this project.

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 build.sbt:

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

Examples

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 <- Slf4jLogger.create[F]
    _ <- logger.info("Logging at start of safelyDoThings")
    something <- Sync[F].delay(println("I could do anything"))
      .onError{case e => logger.error(e)("Something Went Wrong in safelyDoThings")}
    _ <- logger.info("Logging at end of safelyDoThings")
  } yield something

  def passForEasierUse[F[_]: Sync: Logger] = for {
    _ <- Logger[F].info("Logging at start of passForEasierUse")
    something <- Sync[F].delay(println("I could do anything"))
      .onError{case e => Logger[F].error(e)("Something Went Wrong in passForEasierUse")}
    _ <- Logger[F].info("Logging at end of passForEasierUse")
  } yield something
}

Versions

Version
1.1.1
1.0.1
1.0.0
1.0.0-RC3
1.0.0-RC2
1.0.0-RC1
0.4.0-M2
0.4.0-M1
0.3.0
0.3.0-M2
0.3.0-M1
0.2.0
0.2.0-RC2
0.2.0-RC1
0.2.0-M1
0.1.1
0.1.0
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3