log4effect

Logging with Cats Effect

License

License

Categories

Categories

Scala Languages
GroupId

GroupId

io.scalaland
ArtifactId

ArtifactId

log4effect_2.13
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

log4effect
Logging with Cats Effect
Project Organization

Project Organization

io.scalaland
Source Code Management

Source Code Management

https://github.com/scalalandio/log4effect

Download log4effect_2.13

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1
org.typelevel : cats-core_2.13 jar 2.0.0
org.typelevel : cats-effect_2.13 jar 2.0.0
com.typesafe.scala-logging : scala-logging_2.13 jar 3.9.2

test (3)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.2.3
org.specs2 : specs2-core_2.13 jar 4.7.1
org.specs2 : specs2-scalacheck_2.13 jar 4.7.1

Project Modules

There are no modules declared in this project.

log4effect

https://travis-ci.org/scalalandio/log4effect Maven Central License

If you missed some syntax for logging with Cats Effect, then here it is.

Getting started

Library is available for Scala 2.11, 2.12, 2.13.

Add it with:

libraryDependencies += "io.scalaland" %% "log4effect" % log4EffectVersion

Usage

Logging is done using Logged type class:

import cats.effect.Sync
import io.scalaland.log4effect.Logged

def operation[F[_]: Sync: Logged] = for {
  a <- Sync[F].defer(1 + 1)
  b <- Sync[F].defer(2 + 2)
  _ <- Logged[F].info(s"a = $a b=$b")
} yield a -> b

If you want you can use interpolator syntax - it assumes that there is cats.Show instance for any value that you use in it.

import cats.implicits._
import io.scalaland.log4effect.Logged
import io.scalaland.log4effect.syntax._

val i = 1
val d = 1.0
val s = "test"

def logs[F[_]: Monad: Logged] = for {
  _ <- trace"$i $d $s"[F]
  _ <- trace"$i $d $s".withEx[F](new Exception("with ex"))
  _ <- debug"$i $d $s"[F]
  _ <- debug"$i $d $s".withEx[F](new Exception("with ex"))
  _ <- info"$i $d $s"[F]
  _ <- info"$i $d $s".withEx[F](new Exception("with ex"))
  _ <- warn"$i $d $s"[F]
  _ <- warn"$i $d $s".withEx[F](new Exception("with ex"))
  _ <- error"$i $d $s"[F]
  _ <- error"$i $d $s".withEx[F](new Exception("with ex"))
} yield ()

If there is no cats.Show you'd have to call .toString explicitly.

io.scalaland

Scalaland.io

We have another fantastic day writing Scala

Versions

Version
0.1.0