zio / zio-logging

Powerful logging for ZIO 2.0 applications, with compatibility with many logging backends out-of-the-box.
https://zio.dev/zio-logging/
Apache License 2.0
174 stars 81 forks source link

zio logging slf4j bridge fails on ZIO 2.1.1 #845

Closed ognelis closed 4 months ago

ognelis commented 4 months ago

Reproduce example:

import org.slf4j.LoggerFactory
import zio._
import zio.logging.consoleJsonLogger
import zio.logging.slf4j.bridge.Slf4jBridge

object HelloWorld extends ZIOAppDefault {

  override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] =
    Runtime.removeDefaultLoggers >>> consoleJsonLogger() >+> Slf4jBridge.initialize

  override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] = ZIO.attempt {
    val logger = LoggerFactory.getLogger("HelloWorld")
    logger.info("Hello")
  }.cause.map(_.prettyPrint).debug
}

Stack trace:

Exception in thread "zio-fiber-700445110" java.lang.NoSuchMethodError: 'java.lang.Object zio.internal.FiberRuntime.getFiberRef(zio.FiberRef, zio.Unsafe)'
    at zio.logging.slf4j.bridge.ZioLoggerRuntime.$anonfun$log$1(ZioLoggerRuntime.scala:71)
    at zio.logging.slf4j.bridge.ZioLoggerRuntime.$anonfun$log$1$adapted(ZioLoggerRuntime.scala:35)
    at zio.Unsafe$.unsafe(Unsafe.scala:37)
    at zio.logging.slf4j.bridge.ZioLoggerRuntime.log(ZioLoggerRuntime.scala:35)
    at org.slf4j.impl.ZioLoggerFactory.log(ZioLoggerFactory.scala:40)
    at org.slf4j.impl.ZioLogger.log(ZioLogger.scala:30)
    at org.slf4j.helpers.ZioLoggerBase.logWithThrowable(ZioLoggerBase.java:32)
    at org.slf4j.helpers.ZioLoggerBase.info(ZioLoggerBase.java:158)
    at HelloWorld$.$anonfun$run$1(HelloWorld.scala:13)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at zio.ZIOCompanionVersionSpecific.$anonfun$attempt$1(ZIOCompanionVersionSpecific.scala:100)
    at <empty>.HelloWorld.run(HelloWorld.scala:11)

Internal implementation of FiberRuntime(zio 2.0.x) isn't binary compatible with 2.1.1 , so to fix the issue it's enough to update dependency.

ognelis commented 4 months ago

Fixed