doobie icon indicating copy to clipboard operation
doobie copied to clipboard

Effectful logging

Open eugkhp opened this issue 5 years ago • 4 comments

Is there any way i could do logs as effects? Currently LogHanlder is final case class LogHandler(unsafeRun: LogEvent => Unit), i was wondering if i could wrap it some to make it "safe"? final case class LogHandler(run: LogEvent => F[Unit]). And then use it somewhat like that:

class SQLLogger[F[_]: Sync] { // or smth that i can run
    val effectfulLogger: LogHandler = {
      val myLogger: Logger = Logs.sync[F, F].byName("my sql logger") // https://github.com/TinkoffCreditSystems/tofu/tree/master/logging
      LogHandler {
        case Success(s, a, e1, e2) =>
          myLogger.info(s"${s}")
      }
    }
  }

eugkhp avatar Feb 21 '20 21:02 eugkhp

The current LogHandler is probably going away, to be replaced with a logging effect that enters via the transactor. For now you could hack this up with an Effect constraint since you can .unsafeRunSync anything with that constraint. Doesn't buy you much.

tpolecat avatar Feb 21 '20 22:02 tpolecat

In #1566 we now have effectful logging (through providing a LogHandlerM to the interpreter).

Which is also a good time to remove the old LogHandler (due to its less idea interface of unsafeRun: LogEvent => Unit).

If we go ahead with the removal of LogHandler we'll also remove the ability for users to change how each Query/Update is logged. I haven't really needed it, but would like to hear examples of the contrary.

Idea: Add a field label: String to Query/Update which is passed through the LogEvent interface. This makes it very easy for the LogHandlerM implementation to skip logging certain queries.

jatcwang avatar Jul 27 '22 23:07 jatcwang

We do use on demand logging extensively it's very helpful for troubleshooting: a service call which results in a db call, has an additional param which when provided enables logging and service collects logs (including doobie logs) and return them as part of response For majority of the the calls we don't need those logs, only for some sampling or debugging/troubleshooting

jozic avatar Jul 28 '22 13:07 jozic

@jozic Thanks for your input. Do you think my idea would work well for your usecase?

jatcwang avatar Jul 28 '22 13:07 jatcwang

Looks like this can be closed as completed in RC3.

satorg avatar Jun 21 '23 18:06 satorg

Thanks!

jatcwang avatar Jun 22 '23 09:06 jatcwang