izumi icon indicating copy to clipboard operation
izumi copied to clipboard

Add CE3 Support

Open neko-kai opened this issue 4 years ago • 4 comments

neko-kai avatar Apr 28 '21 23:04 neko-kai

val cats_effect = "2.5.0" to val cats_effect = "3.1.0"

please 🐙 possible to add a fast fix till support? If not it's still ok

Jacke avatar Apr 30 '21 00:04 Jacke

@Jacke cats-effect 3.0 was a full rewrite that massively changed every typeclass in the hierarchy in an incompatible way and moved or changed nearly every single method. Updating is unfortunately not as easy as just incrementing the version and will require breaking changes in BIO hierarchy itself as well

neko-kai avatar Apr 30 '21 00:04 neko-kai

@neko-kai Oh, I see. Anyway, I wish you to succeed with this. Thanks for this amazing DI tool. Love to use it

Jacke avatar Apr 30 '21 14:04 Jacke

For those who want to use logstage with CE3 right now, here is the simple snippet that could be used as replacement for LogIOStrict.fromLogger:

LogIOStrictCE3
package example.logging

import cats.effect.Sync
import izumi.fundamentals.platform.language.CodePositionMaterializer
import izumi.logstage.api.Log
import izumi.logstage.api.Log.{ Context, Entry }
import izumi.logstage.api.logger.AbstractLogger
import logstage.Level
import logstage.strict.LogIOStrict

class LogIOStrictCE3[F[_]](l: AbstractLogger)(implicit F: Sync[F]) extends LogIOStrict[F] {
  import F.delay

  override def log(entry: Log.Entry): F[Unit] = delay(l.log(entry))

  override def log(
    logLevel: Log.Level
  )(messageThunk: => Log.Message)(implicit pos: CodePositionMaterializer): F[Unit] =
    delay(l.log(logLevel)(messageThunk)(pos))

  override def withCustomContext(context: Log.CustomContext): LogIOStrict[F] =
    new LogIOStrictCE3[F](l.withCustomContext(context))

  override def unsafeLog(entry: Log.Entry): F[Unit] = delay(l.unsafeLog(entry))

  override def acceptable(loggerId: Log.LoggerId, logLevel: Level): F[Boolean] =
    delay(l.acceptable(loggerId, logLevel))

  override def acceptable(logLevel: Level)(implicit pos: CodePositionMaterializer): F[Boolean] =
    delay(l.acceptable(logLevel)(pos))

  override def createEntry(
    logLevel: Level,
    message: Log.Message
  )(implicit pos: CodePositionMaterializer): F[Log.Entry] =
    delay(Entry.create(logLevel, message)(pos))

  override def createContext(
    logLevel: Level,
    customContext: Log.CustomContext
  )(implicit pos: CodePositionMaterializer): F[Log.Context] =
    delay(Context.recordContext(logLevel, customContext)(pos))
}

object LogIOStrictCE3 {
  def fromLogger[F[_] : Sync](logger: AbstractLogger): LogIOStrict[F] = new LogIOStrictCE3(logger)
}

IndiscriminateCoding avatar Dec 12 '21 17:12 IndiscriminateCoding

Done in 1.1.0-M2

neko-kai avatar Sep 04 '22 14:09 neko-kai