pekko icon indicating copy to clipboard operation
pekko copied to clipboard

LoggingAdapter with ActorSystem and class broken in scala 3

Open TjarkoG opened this issue 1 year ago • 6 comments

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

TjarkoG avatar Oct 21 '24 11:10 TjarkoG

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.

pjfanning avatar Oct 21 '24 11:10 pjfanning

Similar issue - https://github.com/akka/akka-grpc/issues/1396

pjfanning avatar Oct 21 '24 11:10 pjfanning

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

TjarkoG avatar Oct 21 '24 11:10 TjarkoG

I found a comment on an issue suggesting that Logging(actorSystem, getClass)(org.apache.pekko.event.LogSource.fromClass) may work.

pjfanning avatar Oct 21 '24 11:10 pjfanning

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?

TjarkoG avatar Oct 21 '24 11:10 TjarkoG

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

raboof avatar Oct 21 '24 11:10 raboof