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

In Scala3, using a non-inline variable-length parameter doesn't print correctly #436

Open
jxnu-liguobin opened this issue Mar 1, 2024 · 1 comment · May be fixed by #433
Open

In Scala3, using a non-inline variable-length parameter doesn't print correctly #436

jxnu-liguobin opened this issue Mar 1, 2024 · 1 comment · May be fixed by #433
Labels

Comments

@jxnu-liguobin
Copy link
Collaborator

          FYI in case someone else also runs into this, when using Scala 3 and varargs with `:_*` (or just `*` using Scala 3 syntax) the code compiles with scala-logging 3.9.4 and 3.9.5, but doesn't actually pass the values to the underlying logger. You can check following script with scala-cli:
//> using dep "com.typesafe.scala-logging::scala-logging:3.9.4"
//> using dep "ch.qos.logback:logback-classic:1.5.1"

import com.typesafe.scalalogging.LazyLogging

object Test extends LazyLogging {
  def log(): Unit = {
    val args = Seq("1", "2")
    logger.info("test {} {}", args:_*)
  }
}
Test.log()

when running with --scala-version 2.13.12 it will print "test 1 2" and with --scala-version 3.3.1 just "test {} {}". With scala-logging 3.9.5 it won't compile on 2.13 at all

I think the issue for Scala 3 is in this part of the macro:
https://github.com/lightbend-labs/scala-logging/blob/main/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala#L279

Originally posted by @SakulK in #354 (comment)

@jxnu-liguobin jxnu-liguobin linked a pull request Mar 1, 2024 that will close this issue
@jxnu-liguobin
Copy link
Collaborator Author

jxnu-liguobin commented Mar 1, 2024

As discussed by pr #433,

    val args = Seq("1", "2")
    logger.info("test {} {}", args:_*)

It is not currently supported in scala 3. #433 supports this by hardcoding it, but another way is to add a specific API that doesn't include formatArgs

But it's ok if args is an inline Seq

    inline def args = Seq("1", "2")
    logger.info("test {} {}", args:_*)

jxnu-liguobin added a commit that referenced this issue Mar 2, 2024
@jxnu-liguobin jxnu-liguobin linked a pull request Mar 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant