All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.odin.loggers.ContramapLogger.scala Maven / Gradle / Ivy

package io.odin.loggers

import cats.Monad
import cats.effect.kernel.Clock
import io.odin.{Level, Logger, LoggerMessage}

/**
  * Apply given function to each `LoggerMessage` before passing it to the next logger
  */
case class ContramapLogger[F[_]: Clock: Monad](f: LoggerMessage => LoggerMessage, inner: Logger[F])
    extends DefaultLogger[F](inner.minLevel) {
  def submit(msg: LoggerMessage): F[Unit] = inner.log(f(msg))

  override def submit(msgs: List[LoggerMessage]): F[Unit] = inner.log(msgs.map(f))

  def withMinimalLevel(level: Level): Logger[F] = copy(inner = inner.withMinimalLevel(level))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy