From 345ab50f8a9f68960663a4b366a2963186bc4863 Mon Sep 17 00:00:00 2001 From: John Duffell Date: Tue, 17 Oct 2023 22:38:26 +0100 Subject: [PATCH 1/2] define the scala 2 macros in the scala 3 module --- build.sbt | 116 +++++++++++------- .../src}/main/resources/LICENSE-2.0.txt | 0 .../typesafe/scalalogging/LoggerImpl.scala | 85 +++++++++++++ .../LoggerTakingImplicitImpl.scala | 86 +++++++++++++ .../typesafe/scalalogging/LoggerImpl.scala | 84 +++++++++++++ .../typesafe/scalalogging/LoggerMacro.scala | 0 .../LoggerTakingImplicitImpl.scala | 84 +++++++++++++ .../LoggerTakingImplicitMacro.scala | 0 .../com/typesafe/scalalogging/Logger.scala | 0 .../scalalogging/LoggerTakingImplicit.scala | 0 .../com/typesafe/scalalogging/Logging.scala | 0 .../com/typesafe/scalalogging/package.scala | 0 {src => main/src}/test/resources/logback.xml | 0 .../typesafe/scalalogging/LoggerSpec.scala | 0 .../LoggerTakingImplicitSpec.scala | 0 .../scalalogging/LoggerWithMarkerSpec.scala | 0 .../LoggerWithTaggedArgsSpec.scala | 0 .../scalalogging/Scala2LoggerMacro.scala | 6 +- .../Scala2LoggerTakingImplicitMacro.scala | 4 +- .../typesafe/scalalogging/LoggerImpl.scala | 85 ------------- .../LoggerTakingImplicitImpl.scala | 86 ------------- 21 files changed, 413 insertions(+), 223 deletions(-) rename {src => main/src}/main/resources/LICENSE-2.0.txt (100%) create mode 100644 main/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala create mode 100644 main/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala rename {src => main/src}/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala (59%) rename {src => main/src}/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala (100%) rename {src => main/src}/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala (60%) rename {src => main/src}/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala (100%) rename {src => main/src}/main/scala/com/typesafe/scalalogging/Logger.scala (100%) rename {src => main/src}/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala (100%) rename {src => main/src}/main/scala/com/typesafe/scalalogging/Logging.scala (100%) rename {src => main/src}/main/scala/com/typesafe/scalalogging/package.scala (100%) rename {src => main/src}/test/resources/logback.xml (100%) rename {src => main/src}/test/scala/com/typesafe/scalalogging/LoggerSpec.scala (100%) rename {src => main/src}/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala (100%) rename {src => main/src}/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala (100%) rename {src => main/src}/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala (100%) rename src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala => scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerMacro.scala (98%) rename src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala => scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerTakingImplicitMacro.scala (99%) delete mode 100644 src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala delete mode 100644 src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala diff --git a/build.sbt b/build.sbt index 10cbfbe..fd16d5a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,55 +1,77 @@ // basics -name := "scala-logging" -crossScalaVersions := Seq("3.3.1", "2.11.12", "2.12.18", "2.13.12") -scalaVersion := crossScalaVersions.value.head -ThisBuild / versionScheme := Some("early-semver") -scalacOptions ++= Seq( - "-unchecked", - "-deprecation", - "-language:_", - "-encoding", "UTF-8", - "-Ywarn-unused" -) -incOptions := incOptions.value.withLogRecompileOnMacro(false) +val scala213 = "2.13.12" +val scala3 = "3.4.0-RC1-bin-20231016-69e1338-NIGHTLY" //TODO 3.3.2 or 3.4.0 +val scala2 = Seq("2.11.12", "2.12.18", scala213) val isScala3 = Def.setting { CrossVersion.partialVersion(scalaVersion.value).exists(_._1 != 2) } -libraryDependencies ++= Dependencies.scalaLogging(scalaVersion.value, isScala3.value) -initialCommands := """|import com.typesafe.scalalogging._ - |import org.slf4j.{ Logger => Underlying, _ }""".stripMargin - -// OSGi import com.typesafe.sbt.osgi.SbtOsgi -enablePlugins(SbtOsgi) -osgiSettings -OsgiKeys.bundleSymbolicName := "com.typesafe.scala-logging" -OsgiKeys.privatePackage := Seq() -OsgiKeys.exportPackage := Seq("com.typesafe.scalalogging*") - -// publishing - -organization := "com.typesafe.scala-logging" -sonatypeProfileName := "com.typesafe" -licenses := Seq("Apache 2.0 License" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")) -homepage := Some(url("https://github.com/lightbend/scala-logging")) -Test / publishArtifact := false -pomIncludeRepository := (_ => false) -scmInfo := Some( - ScmInfo(url("https://github.com/lightbend/scala-logging"), "scm:git:git@github.com:lightbend/scala-logging.git") -) -developers := List( - Developer( - id = "hseeberger", - name = "Heiko Seeberger", - email = "", - url = url("http://heikoseeberger.de") - ), - Developer( - id = "analytically", - name = "Mathias Bogaert", - email = "", - url = url("http://twitter.com/analytically") +import sbt.url + +lazy val root = (project in file(".")).aggregate(main, scala2macros) + +lazy val main = (project in file("main")) + .enablePlugins(SbtOsgi) + .settings( + name := "scala-logging", + crossScalaVersions := Seq(scala3) ++ scala2, + scalaVersion := crossScalaVersions.value.head, + ThisBuild / versionScheme := Some("early-semver"), + scalacOptions ++= Seq( + "-unchecked", + "-deprecation", + "-language:_", + "-encoding", "UTF-8", + "-Ywarn-unused" + ), + incOptions := incOptions.value.withLogRecompileOnMacro(false), + libraryDependencies ++= Dependencies.scalaLogging(scalaVersion.value, isScala3.value), + initialCommands := """|import com.typesafe.scalalogging._ + |import org.slf4j.{ Logger => Underlying, _ }""".stripMargin + ).settings( + // OSGi + + osgiSettings + ).settings( + OsgiKeys.bundleSymbolicName := "com.typesafe.scala-logging", + OsgiKeys.privatePackage := Seq(), + OsgiKeys.exportPackage := Seq("com.typesafe.scalalogging*"), + + // publishing + + organization := "com.typesafe.scala-logging", + sonatypeProfileName := "com.typesafe", + licenses := Seq("Apache 2.0 License" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")), + homepage := Some(url("https://github.com/lightbend/scala-logging")), + Test / publishArtifact := false, + pomIncludeRepository := (_ => false), + scmInfo := Some( + ScmInfo(url("https://github.com/lightbend/scala-logging"), "scm:git:git@github.com:lightbend/scala-logging.git") + ), + developers := List( + Developer( + id = "hseeberger", + name = "Heiko Seeberger", + email = "", + url = url("http://heikoseeberger.de") + ), + Developer( + id = "analytically", + name = "Mathias Bogaert", + email = "", + url = url("http://twitter.com/analytically") + ) + ) + + ) + .dependsOn(scala2macros) + +lazy val scala2macros = project + .settings( + name := "scala2macros", + scalaVersion := scala213, + crossScalaVersions := scala2, + libraryDependencies ++= Dependencies.scalaLogging(scalaVersion.value, false), ) -) diff --git a/src/main/resources/LICENSE-2.0.txt b/main/src/main/resources/LICENSE-2.0.txt similarity index 100% rename from src/main/resources/LICENSE-2.0.txt rename to main/src/main/resources/LICENSE-2.0.txt diff --git a/main/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala b/main/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala new file mode 100644 index 0000000..f42a5bb --- /dev/null +++ b/main/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala @@ -0,0 +1,85 @@ +package com.typesafe.scalalogging + +import org.slf4j.Marker +class LoggerImpl { + + // Error + + def error(message: String): Unit = macro Scala2LoggerMacro.errorMessage + + def error(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCause + + def error(message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgs + + def error(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.errorMessageMarker + + def error(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCauseMarker + + def error(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgsMarker + + def whenErrorEnabled(body: Unit): Unit = macro Scala2LoggerMacro.errorCode + + // Warn + + def warn(message: String): Unit = macro Scala2LoggerMacro.warnMessage + + def warn(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCause + + def warn(message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgs + + def warn(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.warnMessageMarker + + def warn(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCauseMarker + + def warn(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgsMarker + + def whenWarnEnabled(body: Unit): Unit = macro Scala2LoggerMacro.warnCode + + // Info + + def info(message: String): Unit = macro Scala2LoggerMacro.infoMessage + + def info(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCause + + def info(message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgs + + def info(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.infoMessageMarker + + def info(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCauseMarker + + def info(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgsMarker + + def whenInfoEnabled(body: Unit): Unit = macro Scala2LoggerMacro.infoCode + + // Debug + + def debug(message: String): Unit = macro Scala2LoggerMacro.debugMessage + + def debug(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCause + + def debug(message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgs + + def debug(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.debugMessageMarker + + def debug(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCauseMarker + + def debug(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgsMarker + + def whenDebugEnabled(body: Unit): Unit = macro Scala2LoggerMacro.debugCode + + // Trace + + def trace(message: String): Unit = macro Scala2LoggerMacro.traceMessage + + def trace(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCause + + def trace(message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgs + + def trace(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.traceMessageMarker + + def trace(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCauseMarker + + def trace(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgsMarker + + def whenTraceEnabled(body: Unit): Unit = macro Scala2LoggerMacro.traceCode +} \ No newline at end of file diff --git a/main/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala b/main/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala new file mode 100644 index 0000000..24c4dc7 --- /dev/null +++ b/main/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala @@ -0,0 +1,86 @@ +package com.typesafe.scalalogging + +import org.slf4j.Marker + +class LoggerTakingImplicitImpl[A] private[scalalogging] { + + // Error + + def error(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessage[A] + + def error(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageCause[A] + + def error(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageArgs[A] + + def error(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageMarker[A] + + def error(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageCauseMarker[A] + + def error(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageArgsMarker[A] + + def whenErrorEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorCode[A] + + // Warn + + def warn(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessage[A] + + def warn(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageCause[A] + + def warn(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageArgs[A] + + def warn(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageMarker[A] + + def warn(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageCauseMarker[A] + + def warn(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageArgsMarker[A] + + def whenWarnEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnCode[A] + + // Info + + def info(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessage[A] + + def info(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageCause[A] + + def info(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageArgs[A] + + def info(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageMarker[A] + + def info(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageCauseMarker[A] + + def info(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageArgsMarker[A] + + def whenInfoEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoCode[A] + + // Debug + + def debug(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessage[A] + + def debug(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageCause[A] + + def debug(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageArgs[A] + + def debug(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageMarker[A] + + def debug(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageCauseMarker[A] + + def debug(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageArgsMarker[A] + + def whenDebugEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugCode[A] + + // Trace + + def trace(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessage[A] + + def trace(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageCause[A] + + def trace(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageArgs[A] + + def trace(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageMarker[A] + + def trace(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageCauseMarker[A] + + def trace(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageArgsMarker[A] + + def whenTraceEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceCode[A] +} \ No newline at end of file diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala b/main/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala similarity index 59% rename from src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala rename to main/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala index 9d32826..f63dc42 100644 --- a/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala +++ b/main/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala @@ -1,6 +1,7 @@ package com.typesafe.scalalogging import org.slf4j.{Marker, Logger as Underlying } +import scala.language.experimental.macros trait LoggerImpl { def underlying: Underlying @@ -54,4 +55,87 @@ trait LoggerImpl { inline def trace(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.traceMessageCauseMarker('underlying, 'marker, 'message, 'cause)} inline def trace(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro.traceMessageArgsMarker('underlying, 'marker, 'message, 'args)} inline def whenTraceEnabled(inline body: Unit): Unit = ${LoggerMacro.traceCode('underlying, 'body)} + + //scala 2 + + // Error + + def error(message: String): Unit = macro Scala2LoggerMacro.errorMessage + + def error(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCause + + def error(message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgs + + def error(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.errorMessageMarker + + def error(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCauseMarker + + def error(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgsMarker + + def whenErrorEnabled(body: Unit): Unit = macro Scala2LoggerMacro.errorCode + + // Warn + + def warn(message: String): Unit = macro Scala2LoggerMacro.warnMessage + + def warn(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCause + + def warn(message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgs + + def warn(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.warnMessageMarker + + def warn(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCauseMarker + + def warn(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgsMarker + + def whenWarnEnabled(body: Unit): Unit = macro Scala2LoggerMacro.warnCode + + // Info + + def info(message: String): Unit = macro Scala2LoggerMacro.infoMessage + + def info(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCause + + def info(message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgs + + def info(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.infoMessageMarker + + def info(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCauseMarker + + def info(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgsMarker + + def whenInfoEnabled(body: Unit): Unit = macro Scala2LoggerMacro.infoCode + + // Debug + + def debug(message: String): Unit = macro Scala2LoggerMacro.debugMessage + + def debug(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCause + + def debug(message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgs + + def debug(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.debugMessageMarker + + def debug(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCauseMarker + + def debug(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgsMarker + + def whenDebugEnabled(body: Unit): Unit = macro Scala2LoggerMacro.debugCode + + // Trace + + def trace(message: String): Unit = macro Scala2LoggerMacro.traceMessage + + def trace(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCause + + def trace(message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgs + + def trace(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.traceMessageMarker + + def trace(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCauseMarker + + def trace(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgsMarker + + def whenTraceEnabled(body: Unit): Unit = macro Scala2LoggerMacro.traceCode + } diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala b/main/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala similarity index 100% rename from src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala rename to main/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala b/main/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala similarity index 60% rename from src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala rename to main/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala index 5e99eec..5dc79d2 100644 --- a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala +++ b/main/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala @@ -1,6 +1,7 @@ package com.typesafe.scalalogging import org.slf4j.{Marker, Logger as Underlying } +import scala.language.experimental.macros trait LoggerTakingImplicitImpl[A] { def underlying: Underlying @@ -119,4 +120,87 @@ trait LoggerTakingImplicitImpl[A] { ${LoggerTakingImplicitMacro.traceMessageArgsMarker('underlying, 'canLogEv, 'marker,'message, 'args)('a)} inline def whenTraceEnabled(inline body: Unit)(implicit inline a: A): Unit = ${LoggerTakingImplicitMacro.traceCode('underlying, 'canLogEv, 'body)('a)} + + //scala 2 + + // Error + + def error(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessage[A] + + def error(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageCause[A] + + def error(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageArgs[A] + + def error(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageMarker[A] + + def error(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageCauseMarker[A] + + def error(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageArgsMarker[A] + + def whenErrorEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorCode[A] + + // Warn + + def warn(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessage[A] + + def warn(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageCause[A] + + def warn(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageArgs[A] + + def warn(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageMarker[A] + + def warn(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageCauseMarker[A] + + def warn(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageArgsMarker[A] + + def whenWarnEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnCode[A] + + // Info + + def info(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessage[A] + + def info(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageCause[A] + + def info(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageArgs[A] + + def info(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageMarker[A] + + def info(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageCauseMarker[A] + + def info(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageArgsMarker[A] + + def whenInfoEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoCode[A] + + // Debug + + def debug(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessage[A] + + def debug(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageCause[A] + + def debug(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageArgs[A] + + def debug(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageMarker[A] + + def debug(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageCauseMarker[A] + + def debug(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageArgsMarker[A] + + def whenDebugEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugCode[A] + + // Trace + + def trace(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessage[A] + + def trace(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageCause[A] + + def trace(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageArgs[A] + + def trace(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageMarker[A] + + def trace(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageCauseMarker[A] + + def trace(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageArgsMarker[A] + + def whenTraceEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceCode[A] + } diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala b/main/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala similarity index 100% rename from src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala rename to main/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala diff --git a/src/main/scala/com/typesafe/scalalogging/Logger.scala b/main/src/main/scala/com/typesafe/scalalogging/Logger.scala similarity index 100% rename from src/main/scala/com/typesafe/scalalogging/Logger.scala rename to main/src/main/scala/com/typesafe/scalalogging/Logger.scala diff --git a/src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala b/main/src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala similarity index 100% rename from src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala rename to main/src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala diff --git a/src/main/scala/com/typesafe/scalalogging/Logging.scala b/main/src/main/scala/com/typesafe/scalalogging/Logging.scala similarity index 100% rename from src/main/scala/com/typesafe/scalalogging/Logging.scala rename to main/src/main/scala/com/typesafe/scalalogging/Logging.scala diff --git a/src/main/scala/com/typesafe/scalalogging/package.scala b/main/src/main/scala/com/typesafe/scalalogging/package.scala similarity index 100% rename from src/main/scala/com/typesafe/scalalogging/package.scala rename to main/src/main/scala/com/typesafe/scalalogging/package.scala diff --git a/src/test/resources/logback.xml b/main/src/test/resources/logback.xml similarity index 100% rename from src/test/resources/logback.xml rename to main/src/test/resources/logback.xml diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala b/main/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala similarity index 100% rename from src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala rename to main/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala b/main/src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala similarity index 100% rename from src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala rename to main/src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala b/main/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala similarity index 100% rename from src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala rename to main/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala b/main/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala similarity index 100% rename from src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala rename to main/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala diff --git a/src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala b/scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerMacro.scala similarity index 98% rename from src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala rename to scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerMacro.scala index dbef6b2..bac8333 100644 --- a/src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala +++ b/scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerMacro.scala @@ -3,9 +3,9 @@ package com.typesafe.scalalogging import org.slf4j.Marker import scala.reflect.macros.blackbox -private[scalalogging] object LoggerMacro { +private[scalalogging] object Scala2LoggerMacro { - type LoggerContext = blackbox.Context { type PrefixType = Logger } + type LoggerContext = blackbox.Context // Error @@ -258,7 +258,7 @@ private[scalalogging] object LoggerMacro { } /** Checks whether `message` is an interpolated string and transforms it into SLF4J string interpolation. */ - private def deconstructInterpolatedMessage(c: LoggerContext)(message: c.Expr[String]) = { + private def deconstructInterpolatedMessage(c: LoggerContext)(message: c.Expr[String]): (c.Expr[String], Seq[c.Expr[Any]]) = { val u: c.universe.type = c.universe // Eww; gross! In 2.13, the `s` interpolator on StringContext became a macro, so we have to look at the pre-macro // expansion tree to recover what the user wrote... diff --git a/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala b/scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerTakingImplicitMacro.scala similarity index 99% rename from src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala rename to scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerTakingImplicitMacro.scala index dcce88c..10594fd 100644 --- a/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala +++ b/scala2macros/src/main/scala/com/typesafe/scalalogging/Scala2LoggerTakingImplicitMacro.scala @@ -3,9 +3,9 @@ package com.typesafe.scalalogging import org.slf4j.Marker import scala.reflect.macros.blackbox -private[scalalogging] object LoggerTakingImplicitMacro { +private[scalalogging] object Scala2LoggerTakingImplicitMacro { - type LoggerContext[A] = blackbox.Context { type PrefixType = LoggerTakingImplicit[A] } + type LoggerContext[A] = blackbox.Context // Error diff --git a/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala b/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala deleted file mode 100644 index f1bfcb8..0000000 --- a/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala +++ /dev/null @@ -1,85 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.Marker -class LoggerImpl { - - // Error - - def error(message: String): Unit = macro LoggerMacro.errorMessage - - def error(message: String, cause: Throwable): Unit = macro LoggerMacro.errorMessageCause - - def error(message: String, args: Any*): Unit = macro LoggerMacro.errorMessageArgs - - def error(marker: Marker, message: String): Unit = macro LoggerMacro.errorMessageMarker - - def error(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.errorMessageCauseMarker - - def error(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.errorMessageArgsMarker - - def whenErrorEnabled(body: Unit): Unit = macro LoggerMacro.errorCode - - // Warn - - def warn(message: String): Unit = macro LoggerMacro.warnMessage - - def warn(message: String, cause: Throwable): Unit = macro LoggerMacro.warnMessageCause - - def warn(message: String, args: Any*): Unit = macro LoggerMacro.warnMessageArgs - - def warn(marker: Marker, message: String): Unit = macro LoggerMacro.warnMessageMarker - - def warn(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.warnMessageCauseMarker - - def warn(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.warnMessageArgsMarker - - def whenWarnEnabled(body: Unit): Unit = macro LoggerMacro.warnCode - - // Info - - def info(message: String): Unit = macro LoggerMacro.infoMessage - - def info(message: String, cause: Throwable): Unit = macro LoggerMacro.infoMessageCause - - def info(message: String, args: Any*): Unit = macro LoggerMacro.infoMessageArgs - - def info(marker: Marker, message: String): Unit = macro LoggerMacro.infoMessageMarker - - def info(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.infoMessageCauseMarker - - def info(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.infoMessageArgsMarker - - def whenInfoEnabled(body: Unit): Unit = macro LoggerMacro.infoCode - - // Debug - - def debug(message: String): Unit = macro LoggerMacro.debugMessage - - def debug(message: String, cause: Throwable): Unit = macro LoggerMacro.debugMessageCause - - def debug(message: String, args: Any*): Unit = macro LoggerMacro.debugMessageArgs - - def debug(marker: Marker, message: String): Unit = macro LoggerMacro.debugMessageMarker - - def debug(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.debugMessageCauseMarker - - def debug(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.debugMessageArgsMarker - - def whenDebugEnabled(body: Unit): Unit = macro LoggerMacro.debugCode - - // Trace - - def trace(message: String): Unit = macro LoggerMacro.traceMessage - - def trace(message: String, cause: Throwable): Unit = macro LoggerMacro.traceMessageCause - - def trace(message: String, args: Any*): Unit = macro LoggerMacro.traceMessageArgs - - def trace(marker: Marker, message: String): Unit = macro LoggerMacro.traceMessageMarker - - def trace(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.traceMessageCauseMarker - - def trace(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.traceMessageArgsMarker - - def whenTraceEnabled(body: Unit): Unit = macro LoggerMacro.traceCode -} \ No newline at end of file diff --git a/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala b/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala deleted file mode 100644 index 070a697..0000000 --- a/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala +++ /dev/null @@ -1,86 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.Marker - -class LoggerTakingImplicitImpl[A] private[scalalogging] { - - // Error - - def error(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessage[A] - - def error(message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessageCause[A] - - def error(message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessageArgs[A] - - def error(marker: Marker, message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessageMarker[A] - - def error(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessageCauseMarker[A] - - def error(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessageArgsMarker[A] - - def whenErrorEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorCode[A] - - // Warn - - def warn(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessage[A] - - def warn(message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessageCause[A] - - def warn(message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessageArgs[A] - - def warn(marker: Marker, message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessageMarker[A] - - def warn(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessageCauseMarker[A] - - def warn(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessageArgsMarker[A] - - def whenWarnEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnCode[A] - - // Info - - def info(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessage[A] - - def info(message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessageCause[A] - - def info(message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessageArgs[A] - - def info(marker: Marker, message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessageMarker[A] - - def info(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessageCauseMarker[A] - - def info(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessageArgsMarker[A] - - def whenInfoEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoCode[A] - - // Debug - - def debug(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessage[A] - - def debug(message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessageCause[A] - - def debug(message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessageArgs[A] - - def debug(marker: Marker, message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessageMarker[A] - - def debug(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessageCauseMarker[A] - - def debug(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessageArgsMarker[A] - - def whenDebugEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugCode[A] - - // Trace - - def trace(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessage[A] - - def trace(message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessageCause[A] - - def trace(message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessageArgs[A] - - def trace(marker: Marker, message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessageMarker[A] - - def trace(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessageCauseMarker[A] - - def trace(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessageArgsMarker[A] - - def whenTraceEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceCode[A] -} \ No newline at end of file From 4b35e9ca8cd9052cc7ff5daf1a2ca2608956191d Mon Sep 17 00:00:00 2001 From: John Duffell Date: Fri, 16 Feb 2024 21:02:30 +0000 Subject: [PATCH 2/2] use released version of scala that includes compiler fix --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index fd16d5a..05ebeb5 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ // basics val scala213 = "2.13.12" -val scala3 = "3.4.0-RC1-bin-20231016-69e1338-NIGHTLY" //TODO 3.3.2 or 3.4.0 +val scala3 = "3.4.0" val scala2 = Seq("2.11.12", "2.12.18", scala213) val isScala3 = Def.setting { CrossVersion.partialVersion(scalaVersion.value).exists(_._1 != 2)