LoggingAdapter with ActorSystem and class broken in scala 3
when migrating from scala 2.13.14 to scala 3.3.0 we're running into an error with the LoggingAdapter.
The setup:
package com.example
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.event.{Logging, LogSource, LoggingAdapter}
class Foo(actorSystem: ActorSystem) {
val bar: LoggingAdapter = Logging(actorSystem, getClass)
}
does compile with scala 2.13.14 but with scala 3.3.0 it runs into the following Error:
Cannot find LogSource for Class[? <: com.example.Foo] please see ScalaDoc for LogSource for how to obtain or construct one..
I found:
org.apache.pekko.event.LogSource.fromAnyClass[T]
But method fromAnyClass in object LogSource does not match type org.apache.pekko.event.LogSource[Class[? <: com.example.Foo]].
val bar: LoggingAdapter = Logging(actorSystem, getClass)
pekko version used is 1.1.2
if this is not a bug and only an error on my side im sorry but i have not found anything on this topic in the docs
Scala 3 is the issue here. It doesn't accept 100% of Scala 2 code.
I usually just change getClass to classOf[MyClass] where MyClass is the name of the class.
I think you can get Logging(actorSystem, getClass) to work by providing the implicit converter explicity. I haven't tried the exact solution but it is something like.
Logging(actorSystem, getClass)(org.apache.pekko.event.LogSource.fromAnyClass)
That Logging constructor takes a 2nd param list where the params are implicits but somehow Scala 3 doesn't find the implied value.
Similar issue - https://github.com/akka/akka-grpc/issues/1396
yes the classOf[Foo] solution was something we've thought of the problem ist that in the actual code we don't have the class yet. In the actual code Foo is a trait and we don't have the implementing class yet but if this will be to complicated we'll just do it in the implementing classes
I found a comment on an issue suggesting that Logging(actorSystem, getClass)(org.apache.pekko.event.LogSource.fromClass) may work.
oh yes it does. thank you. very much and sorry for opening an issue. should we add something bout this in the scaladoc for org. apache. pekko. event.Logging or org. apache. pekko. event.LoggingSource to avoid additional issues about this being created?
should we add something bout this in the scaladoc for org. apache. pekko. event.Logging or org. apache. pekko. event.LoggingSource
I think it'd make sense to keep this issue open until we've improved the docs to make this more clear, indeed