Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggingAdapter with ActorSystem and class broken in scala 3 #1538

Open
TjarkoG opened this issue Oct 21, 2024 · 6 comments
Open

LoggingAdapter with ActorSystem and class broken in scala 3 #1538

TjarkoG opened this issue Oct 21, 2024 · 6 comments

Comments

@TjarkoG
Copy link

TjarkoG commented Oct 21, 2024

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 TjarkoG changed the title LoggingAdapter with ActorSystem and class broken in scala3 LoggingAdapter with ActorSystem and class broken in scala 3 Oct 21, 2024
@pjfanning
Copy link
Contributor

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
Copy link
Contributor

Similar issue - akka/akka-grpc#1396

@TjarkoG
Copy link
Author

TjarkoG commented Oct 21, 2024

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

@pjfanning
Copy link
Contributor

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

@TjarkoG
Copy link
Author

TjarkoG commented Oct 21, 2024

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?

@raboof
Copy link
Member

raboof commented Oct 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants