doobie
doobie copied to clipboard
Effectful logging
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}")
}
}
}
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.
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.
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 Thanks for your input. Do you think my idea would work well for your usecase?
Looks like this can be closed as completed in RC3.
Thanks!