Hi, I’m looking for advice on how to do logging in...
# functional
d
Hi, I’m looking for advice on how to do logging in functional code. Functional -> no side effects -> no logs ;-). Our code is base on Arrow’s IO, so I would appreciate some hints for logging in this context.
r
@dnowak you can also make it poart of your effects by exposing it as a type class:
Copy code
interface Logger<F> {
  val A: Async<F>
  fun info(msg: String): Kind<F, Unit>
}

object IOLogger : Logger<ForIO> {
  override val A = IO.async()
  override fun info(msg: String): IO<Unit> = IO.effect { log(msg) }
}

//...other runtimes like Rx, etc will also be able to provide an impl for it
g
r
A complete library that integrates with slf4j too asn example in scala https://github.com/ChristopherDavenport/log4cats
It also observes F for polymorphism and abstracts what runtime it targets
d
Thank you for all the responses. Right now
flatTap
is all what I need.
👍 1