Skip to main content
Version: 2.0.0-beta24

What to Import

Most Places

import loggerf.core._
import loggerf.syntax.all._
import loggerf.core._ // for Log
import loggerf.syntax.all._ // for log(), log_(), logS(), logS_(), etc.

def foo[F[_]: Log](n: Int): F[int] =
for {
n2 <- bar(n).log(n2 => info(s"n2: $n2"))
} yield n + n2

For Main Method

You need instances for Log when you actually run your program. It's usually only one place where you put the main method.

Log[F] Instance

For the instance of Log[F],

import loggerf.instances.cats._

Instances for Effectie

For the instance of Fx[F] (effectie)

import effectie.instnace.monix3.fx._

CanLog (Logger)

If you use slf4j or logback, get logger-f-slf4j then,

import loggerf.logger._

implicit val canLog: CanLog = Slf4JLogger.slf4JCanLog[MyAppType]
// or
implicit val canLog: CanLog = Slf4JLogger.slf4JCanLog[this.type]

// or
implicit val canLog: CanLog = Slf4JLogger.slf4JCanLog("my-logger-name")

// or
implicit val canLog: CanLog = Slf4JLogger.slf4JCanLogWith(org.slf4j.LoggerFactory.getLogger(getClass))

Example

import cats._
import cats.syntax.all._

import effectie.core._
import effectie.syntax.all._

import loggerf.core._
import loggerf.syntax.all._

trait Foo[F[_]] {
def foo(name: String): F[Unit]
}
object Foo {
def apply[F[_]: Fx: Log: Monad]: Foo[F] = new FooF[F]

private class FooF[F[_]: Fx: Log: Monad] extends Foo[F] {
def foo(name: String): F[Unit] =
for {
_ <- s"Name: $name".logS_(info)
message <- pureOf(s"Hello $name").log(infoA)
_ <- effectOf(println(message))
} yield ()
}
}
import cats.effect._

object MyApp extends IOApp.Simple {
import loggerf.logger._
implicit val canLog: CanLog = Slf4JLogger.slf4JCanLog[this.type]

import effectie.instances.ce2.fx._
import loggerf.instances.cats._

def run: IO[Unit] =
Foo[IO].foo("Kevin")

}