Provide empty logger as instance for .updateService
domdorn opened this issue · 2 comments
domdorn commented
today I needed to deactivate logging for a certain effect and noticed that we only have the Logging.ignore
layer but not a simple EmptyLogger instance I can use with .updateService
import zio.{UIO, ZIO}
import zio.logging.{LogContext, Logger}
object EmptyLogger extends Logger[String] {
override def locally[R1, E, A1](f: LogContext => LogContext)(in: ZIO[R1, E, A1]): ZIO[R1, E, A1] = in
override def log(line: => String): UIO[Unit] = ZIO.unit
override def logContext: UIO[LogContext] = ZIO.succeed(LogContext.empty)
}
I use it in my streams like this:
cockpitZR <-
ZStream
.fromEffect(
(for {
result <- effectWithDisabledLogging(....)
.updateService[zio.logging.Logger[String]](_ => EmptyLogger)
_ <- someOtherEffectWithNormalLogging(...)
} yield result)
.tapCause(e => zio.logging.log.error("failed to calculate ...", e))
)
Maybe we can include this in a straightforward way into the library?
pshemass commented
that's good idea however I would probably use different name something like
import zio.{UIO, ZIO}
import zio.logging.{LogContext, Logger}
object IgnoreLogger extends Logger[String] {
override def locally[R1, E, A1](f: LogContext => LogContext)(in: ZIO[R1, E, A1]): ZIO[R1, E, A1] = in
override def log(line: => String): UIO[Unit] = ZIO.unit
override def logContext: UIO[LogContext] = ZIO.succeed(LogContext.empty)
}
feel free to open open PR
justcoon commented
with zio 2, Runtime.removeDefaultLoggers
should remove all loggers
closing this ticket as it was related to zio 1 implementation, fill free to open new one, if there are some other issues