From a5e76ba93fa854a132e79454cba3a417e1b2cc38 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 1 Apr 2022 13:40:53 -0600 Subject: [PATCH 1/2] Add support for scala 2/3 compatible macros A lot of things were removed that the original scala-logging repo was leveraging heavily: - Build/deploy definitions (these can easily be restored) - LoggerTakingImplicits (couldn't get the version-unifying project to build with implicits being involved in the macros for some reason) - Scala 2.11 and 2.12 support (cross-version macro support is limited to very specific versions of Scala 2.13 and Scala 3) This commit represents the beginning of the Lucid Software branch of the scala-logging library. Due to the major changes, it should never be merged back into the scala-logging library, but it can serve as a starting point for those interested in attempting to bridge the compatibility gap between this library and Scala 2 + 3 in a less destructive way. --- .../typesafe/scalalogging/Scala2Spec.scala | 39 ++ .../typesafe/scalalogging/Scala3Spec.scala | 39 ++ build.sbt | 87 ++-- project/Dependencies.scala | 4 +- project/build.properties | 2 +- project/plugins.sbt | 3 - .../src}/main/resources/LICENSE-2.0.txt | 0 .../com/typesafe/scalalogging/Logger.scala | 16 +- .../typesafe/scalalogging/LoggerImpl.scala | 126 +++++ .../com/typesafe/scalalogging/Logging.scala | 0 .../com/typesafe/scalalogging/package.scala | 0 .../src}/test/resources/logback.xml | 0 .../typesafe/scalalogging/LoggerSpec.scala | 74 +-- .../scalalogging/LoggerWithMarkerSpec.scala | 10 +- .../LoggerWithTaggedArgsSpec.scala | 11 +- .../typesafe/scalalogging/LoggerMacro2.scala | 6 +- scalalogging3/src/.editorconfig | 12 + .../typesafe/scalalogging/LoggerMacro3.scala | 2 +- .../typesafe/scalalogging/LoggerImpl.scala | 85 ---- .../LoggerTakingImplicitImpl.scala | 86 ---- .../LoggerTakingImplicitMacro.scala | 439 ------------------ .../typesafe/scalalogging/LoggerImpl.scala | 57 --- .../LoggerTakingImplicitImpl.scala | 122 ----- .../LoggerTakingImplicitMacro.scala | 311 ------------- .../scalalogging/LoggerTakingImplicit.scala | 14 - .../LoggerTakingImplicitSpec.scala | 403 ---------------- 26 files changed, 284 insertions(+), 1664 deletions(-) create mode 100644 app2/src/test/scala/com/typesafe/scalalogging/Scala2Spec.scala create mode 100644 app3/src/test/scala/com/typesafe/scalalogging/Scala3Spec.scala rename {src => scalalogging/src}/main/resources/LICENSE-2.0.txt (100%) rename {src => scalalogging/src}/main/scala/com/typesafe/scalalogging/Logger.scala (76%) create mode 100644 scalalogging/src/main/scala/com/typesafe/scalalogging/LoggerImpl.scala rename {src => scalalogging/src}/main/scala/com/typesafe/scalalogging/Logging.scala (100%) rename {src => scalalogging/src}/main/scala/com/typesafe/scalalogging/package.scala (100%) rename {src => scalalogging/src}/test/resources/logback.xml (100%) rename {src => scalalogging/src}/test/scala/com/typesafe/scalalogging/LoggerSpec.scala (89%) rename {src => scalalogging/src}/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala (98%) rename {src => scalalogging/src}/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala (91%) rename src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala => scalalogging2/src/main/scala/com/typesafe/scalalogging/LoggerMacro2.scala (98%) create mode 100644 scalalogging3/src/.editorconfig rename src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala => scalalogging3/src/main/scala/com/typesafe/scalalogging/LoggerMacro3.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 delete mode 100644 src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala delete mode 100644 src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala delete mode 100644 src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala delete mode 100644 src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala delete mode 100644 src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala delete mode 100644 src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala diff --git a/app2/src/test/scala/com/typesafe/scalalogging/Scala2Spec.scala b/app2/src/test/scala/com/typesafe/scalalogging/Scala2Spec.scala new file mode 100644 index 00000000..787c27c8 --- /dev/null +++ b/app2/src/test/scala/com/typesafe/scalalogging/Scala2Spec.scala @@ -0,0 +1,39 @@ +package com.typesafe.scalalogging + +import org.mockito.Mockito._ +import org.scalatest.wordspec.AnyWordSpec +import org.scalatestplus.mockito.MockitoSugar +import org.slf4j.{ Logger => Underlying } + +class Scala2 extends AnyWordSpec with MockitoSugar { + + "Calling Logger from Scala 2" should { + "work" in { + val f = fixture(_.isInfoEnabled, isEnabled = true) + import f._ + + logger.info("message") + verify(underlying).info("message") + } + } + + private def fixture(p: Underlying => Boolean, isEnabled: Boolean) = new LoggerF(p, isEnabled) + private class LoggerF(p: Underlying => Boolean, isEnabled: Boolean) { + val msg = "msg" + val cause = new RuntimeException("cause") + val arg1 = "arg1" + val arg2 = Integer.valueOf(1) + val arg3 = "arg3" + val arg4 = 4 + val arg4ref = arg4.asInstanceOf[AnyRef] + val arg5 = true + val arg5ref = arg5.asInstanceOf[AnyRef] + val arg6 = 6L + val arg6ref = arg6.asInstanceOf[AnyRef] + val arg7 = new Throwable + val arg7ref = arg7.asInstanceOf[AnyRef] + val underlying = mock[org.slf4j.Logger] + when(p(underlying)).thenReturn(isEnabled) + val logger = Logger(underlying) + } +} diff --git a/app3/src/test/scala/com/typesafe/scalalogging/Scala3Spec.scala b/app3/src/test/scala/com/typesafe/scalalogging/Scala3Spec.scala new file mode 100644 index 00000000..c9fc3e58 --- /dev/null +++ b/app3/src/test/scala/com/typesafe/scalalogging/Scala3Spec.scala @@ -0,0 +1,39 @@ +package com.typesafe.scalalogging + +import org.mockito.Mockito._ +import org.scalatest.wordspec.AnyWordSpec +import org.scalatestplus.mockito.MockitoSugar +import org.slf4j.{ Logger => Underlying } + +class Scala3 extends AnyWordSpec with MockitoSugar { + + "Calling Logger from Scala 3" should { + "work" in { + val f = fixture(_.isInfoEnabled, isEnabled = true) + import f._ + + logger.info("message") + verify(underlying).info("message") + } + } + + private def fixture(p: Underlying => Boolean, isEnabled: Boolean) = new LoggerF(p, isEnabled) + private class LoggerF(p: Underlying => Boolean, isEnabled: Boolean) { + val msg = "msg" + val cause = new RuntimeException("cause") + val arg1 = "arg1" + val arg2 = Integer.valueOf(1) + val arg3 = "arg3" + val arg4 = 4 + val arg4ref = arg4.asInstanceOf[AnyRef] + val arg5 = true + val arg5ref = arg5.asInstanceOf[AnyRef] + val arg6 = 6L + val arg6ref = arg6.asInstanceOf[AnyRef] + val arg7 = new Throwable + val arg7ref = arg7.asInstanceOf[AnyRef] + val underlying = mock[org.slf4j.Logger] + when(p(underlying)).thenReturn(isEnabled) + val logger = Logger(underlying) + } +} diff --git a/build.sbt b/build.sbt index f3fbd21b..465b6c03 100644 --- a/build.sbt +++ b/build.sbt @@ -1,55 +1,42 @@ -// basics +ThisBuild / scalaVersion := "3.0.2" +val scala213 = "2.13.8" -name := "scala-logging" -crossScalaVersions := Seq("3.0.2", "2.11.12", "2.12.15", "2.13.8") -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 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 +lazy val scalalogging2 = project + .settings( + name := "scala-logging2", + scalaVersion := scala213, + libraryDependencies ++= Dependencies.scalaLogging(scala213, false) + ) -import com.typesafe.sbt.osgi.SbtOsgi -enablePlugins(SbtOsgi) -osgiSettings -OsgiKeys.bundleSymbolicName := "com.typesafe.scala-logging" -OsgiKeys.privatePackage := Seq() -OsgiKeys.exportPackage := Seq("com.typesafe.scalalogging*") +lazy val scalalogging3 = project + .settings( + name := "scala-logging3", + scalaVersion := "3.0.2", + libraryDependencies ++= Dependencies.scalaLogging("3.0.2", true) + ) -// publishing +lazy val scalalogging = project + .dependsOn(scalalogging2, scalalogging3) + .settings( + name := "scala-logging", + scalaVersion := "3.0.2", + libraryDependencies ++= Dependencies.scalaLogging("3.0.2", true), + ) -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") +lazy val app2 = project + .dependsOn(scalalogging) + .settings( + name := "app2", + scalaVersion := scala213, + scalacOptions := Seq("-Ytasty-reader"), + libraryDependencies ++= Dependencies.scalaLogging(scala213, false), + libraryDependencies += Library.logbackClassic ) -) + +lazy val app3 = project + .dependsOn(scalalogging) + .settings( + name := "app3", + libraryDependencies ++= Dependencies.scalaLogging("3.0.2", true), + libraryDependencies += Library.logbackClassic + ) \ No newline at end of file diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 34966e48..1dd7c9bb 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -3,8 +3,8 @@ import sbt._ object Version { val logback = "1.2.10" val mockito = "3.2.10.0" - val scalaTest = "3.2.11" - val slf4j = "1.7.36" + val scalaTest = "3.2.10" + val slf4j = "1.7.33" } object Library { diff --git a/project/build.properties b/project/build.properties index c8fcab54..3161d214 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.6.1 diff --git a/project/plugins.sbt b/project/plugins.sbt index 9130ceb4..7ec18435 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1 @@ addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3") -addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.6") -addSbtPlugin("com.scalapenos" % "sbt-prompt" % "1.0.2") -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") diff --git a/src/main/resources/LICENSE-2.0.txt b/scalalogging/src/main/resources/LICENSE-2.0.txt similarity index 100% rename from src/main/resources/LICENSE-2.0.txt rename to scalalogging/src/main/resources/LICENSE-2.0.txt diff --git a/src/main/scala/com/typesafe/scalalogging/Logger.scala b/scalalogging/src/main/scala/com/typesafe/scalalogging/Logger.scala similarity index 76% rename from src/main/scala/com/typesafe/scalalogging/Logger.scala rename to scalalogging/src/main/scala/com/typesafe/scalalogging/Logger.scala index c1310cee..85822844 100644 --- a/src/main/scala/com/typesafe/scalalogging/Logger.scala +++ b/scalalogging/src/main/scala/com/typesafe/scalalogging/Logger.scala @@ -17,8 +17,8 @@ object Logger { /** * Create a [[LoggerTakingImplicit]] wrapping the given underlying `org.slf4j.Logger`. */ - def takingImplicit[A](underlying: Underlying)(implicit ev: CanLog[A]): LoggerTakingImplicit[A] = - new LoggerTakingImplicit[A](underlying) + // def takingImplicit[A](underlying: Underlying)(implicit ev: CanLog[A]): LoggerTakingImplicit[A] = + // new LoggerTakingImplicit[A](underlying) /** * Create a [[Logger]] for the given name. @@ -37,8 +37,8 @@ object Logger { * val logger = Logger.takingImplicit[CorrelationId]("application") * }}} */ - def takingImplicit[A](name: String)(implicit ev: CanLog[A]): LoggerTakingImplicit[A] = - new LoggerTakingImplicit[A](LoggerFactory.getLogger(name)) + // def takingImplicit[A](name: String)(implicit ev: CanLog[A]): LoggerTakingImplicit[A] = + // new LoggerTakingImplicit[A](LoggerFactory.getLogger(name)) /** * Create a [[Logger]] wrapping the created underlying `org.slf4j.Logger`. @@ -49,8 +49,8 @@ object Logger { /** * Create a [[LoggerTakingImplicit]] wrapping the created underlying `org.slf4j.Logger`. */ - def takingImplicit[A](clazz: Class[_])(implicit ev: CanLog[A]): LoggerTakingImplicit[A] = - new LoggerTakingImplicit[A](LoggerFactory.getLogger(clazz.getName)) + // def takingImplicit[A](clazz: Class[_])(implicit ev: CanLog[A]): LoggerTakingImplicit[A] = + // new LoggerTakingImplicit[A](LoggerFactory.getLogger(clazz.getName)) /** * Create a [[Logger]] for the runtime class wrapped by the implicit class @@ -71,8 +71,8 @@ object Logger { * val logger = Logger.takingImplicit[MyClass, CorrelationId] * }}} */ - def takingImplicit[T, A](implicit ct: ClassTag[T], ev: CanLog[A]): LoggerTakingImplicit[A] = - new LoggerTakingImplicit[A](LoggerFactory.getLogger(ct.runtimeClass.getName.stripSuffix("$"))) + // def takingImplicit[T, A](implicit ct: ClassTag[T], ev: CanLog[A]): LoggerTakingImplicit[A] = + // new LoggerTakingImplicit[A](LoggerFactory.getLogger(ct.runtimeClass.getName.stripSuffix("$"))) } /** diff --git a/scalalogging/src/main/scala/com/typesafe/scalalogging/LoggerImpl.scala b/scalalogging/src/main/scala/com/typesafe/scalalogging/LoggerImpl.scala new file mode 100644 index 00000000..0d15b55b --- /dev/null +++ b/scalalogging/src/main/scala/com/typesafe/scalalogging/LoggerImpl.scala @@ -0,0 +1,126 @@ +package com.typesafe.scalalogging + +import com.typesafe.scalalogging.{LoggerMacro2, LoggerMacro3} + +import org.slf4j.{Marker, Logger as Underlying } + +trait LoggerImpl { + def underlying: Underlying + + import scala.language.experimental.macros + + // Error + + def error(message: String): Unit = macro LoggerMacro2.errorMessage + inline def error(inline message: String): Unit = ${LoggerMacro3.errorMessage('underlying, 'message)} + + def error(message: String, cause: Throwable): Unit = macro LoggerMacro2.errorMessageCause + inline def error(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.errorMessageCause('underlying, 'message, 'cause)} + + def error(message: String, args: Any*): Unit = macro LoggerMacro2.errorMessageArgs + inline def error(inline message: String, inline args: Any*): Unit = ${LoggerMacro3.errorMessageArgs('underlying, 'message, 'args)} + + def error(marker: Marker, message: String): Unit = macro LoggerMacro2.errorMessageMarker + inline def error(inline marker: Marker, inline message: String): Unit = ${LoggerMacro3.errorMessageMarker('underlying, 'marker, 'message)} + + def error(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro2.errorMessageCauseMarker + inline def error(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.errorMessageCauseMarker('underlying, 'marker, 'message, 'cause)} + + def error(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro2.errorMessageArgsMarker + inline def error(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro3.errorMessageArgsMarker('underlying, 'marker, 'message, 'args)} + + def whenErrorEnabled(body: Unit): Unit = macro LoggerMacro2.errorCode + inline def whenErrorEnabled(inline body: Unit): Unit = ${LoggerMacro3.errorCode('underlying, 'body)} + + // Warn + + def warn(message: String): Unit = macro LoggerMacro2.warnMessage + inline def warn(inline message: String): Unit = ${LoggerMacro3.warnMessage('underlying, 'message)} + + def warn(message: String, cause: Throwable): Unit = macro LoggerMacro2.warnMessageCause + inline def warn(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.warnMessageCause('underlying, 'message, 'cause)} + + def warn(message: String, args: Any*): Unit = macro LoggerMacro2.warnMessageArgs + inline def warn(inline message: String, inline args: Any*): Unit = ${LoggerMacro3.warnMessageArgs('underlying, 'message, 'args)} + + def warn(marker: Marker, message: String): Unit = macro LoggerMacro2.warnMessageMarker + inline def warn(inline marker: Marker, inline message: String): Unit = ${LoggerMacro3.warnMessageMarker('underlying, 'marker, 'message)} + + def warn(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro2.warnMessageCauseMarker + inline def warn(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.warnMessageCauseMarker('underlying, 'marker, 'message, 'cause)} + + def warn(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro2.warnMessageArgsMarker + inline def warn(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro3.warnMessageArgsMarker('underlying, 'marker, 'message, 'args)} + + def whenWarnEnabled(body: Unit): Unit = macro LoggerMacro2.warnCode + inline def whenWarnEnabled(inline body: Unit): Unit = ${LoggerMacro3.warnCode('underlying, 'body)} + + // Info + + def info(message: String): Unit = macro LoggerMacro2.infoMessage + inline def info(inline message: String): Unit = ${LoggerMacro3.infoMessage('underlying, 'message)} + + def info(message: String, cause: Throwable): Unit = macro LoggerMacro2.infoMessageCause + inline def info(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.infoMessageCause('underlying, 'message, 'cause)} + + def info(message: String, args: Any*): Unit = macro LoggerMacro2.infoMessageArgs + inline def info(inline message: String, inline args: Any*): Unit = ${LoggerMacro3.infoMessageArgs('underlying, 'message, 'args)} + + def info(marker: Marker, message: String): Unit = macro LoggerMacro2.infoMessageMarker + inline def info(inline marker: Marker, inline message: String): Unit = ${LoggerMacro3.infoMessageMarker('underlying, 'marker, 'message)} + + def info(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro2.infoMessageCauseMarker + inline def info(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.infoMessageCauseMarker('underlying, 'marker, 'message, 'cause)} + + def info(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro2.infoMessageArgsMarker + inline def info(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro3.infoMessageArgsMarker('underlying, 'marker, 'message, 'args)} + + def whenInfoEnabled(body: Unit): Unit = macro LoggerMacro2.infoCode + inline def whenInfoEnabled(inline body: Unit): Unit = ${LoggerMacro3.infoCode('underlying, 'body)} + + // Debug + + def debug(message: String): Unit = macro LoggerMacro2.debugMessage + inline def debug(inline message: String): Unit = ${LoggerMacro3.debugMessage('underlying, 'message)} + + def debug(message: String, cause: Throwable): Unit = macro LoggerMacro2.debugMessageCause + inline def debug(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.debugMessageCause('underlying, 'message, 'cause)} + + def debug(message: String, args: Any*): Unit = macro LoggerMacro2.debugMessageArgs + inline def debug(inline message: String, inline args: Any*): Unit = ${LoggerMacro3.debugMessageArgs('underlying, 'message, 'args)} + + def debug(marker: Marker, message: String): Unit = macro LoggerMacro2.debugMessageMarker + inline def debug(inline marker: Marker, inline message: String): Unit = ${LoggerMacro3.debugMessageMarker('underlying, 'marker, 'message)} + + def debug(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro2.debugMessageCauseMarker + inline def debug(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.debugMessageCauseMarker('underlying, 'marker, 'message, 'cause)} + + def debug(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro2.debugMessageArgsMarker + inline def debug(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro3.debugMessageArgsMarker('underlying, 'marker, 'message, 'args)} + + def whenDebugEnabled(body: Unit): Unit = macro LoggerMacro2.debugCode + inline def whenDebugEnabled(inline body: Unit): Unit = ${LoggerMacro3.debugCode('underlying, 'body)} + + // Trace + + def trace(message: String): Unit = macro LoggerMacro2.traceMessage + inline def trace(inline message: String): Unit = ${LoggerMacro3.traceMessage('underlying, 'message)} + + def trace(message: String, cause: Throwable): Unit = macro LoggerMacro2.traceMessageCause + inline def trace(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.traceMessageCause('underlying, 'message, 'cause)} + + def trace(message: String, args: Any*): Unit = macro LoggerMacro2.traceMessageArgs + inline def trace(inline message: String, inline args: Any*): Unit = ${LoggerMacro3.traceMessageArgs('underlying, 'message, 'args)} + + def trace(marker: Marker, message: String): Unit = macro LoggerMacro2.traceMessageMarker + inline def trace(inline marker: Marker, inline message: String): Unit = ${LoggerMacro3.traceMessageMarker('underlying, 'marker, 'message)} + + def trace(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro2.traceMessageCauseMarker + inline def trace(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro3.traceMessageCauseMarker('underlying, 'marker, 'message, 'cause)} + + def trace(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro2.traceMessageArgsMarker + inline def trace(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro3.traceMessageArgsMarker('underlying, 'marker, 'message, 'args)} + + def whenTraceEnabled(body: Unit): Unit = macro LoggerMacro2.traceCode + inline def whenTraceEnabled(inline body: Unit): Unit = ${LoggerMacro3.traceCode('underlying, 'body)} +} \ No newline at end of file diff --git a/src/main/scala/com/typesafe/scalalogging/Logging.scala b/scalalogging/src/main/scala/com/typesafe/scalalogging/Logging.scala similarity index 100% rename from src/main/scala/com/typesafe/scalalogging/Logging.scala rename to scalalogging/src/main/scala/com/typesafe/scalalogging/Logging.scala diff --git a/src/main/scala/com/typesafe/scalalogging/package.scala b/scalalogging/src/main/scala/com/typesafe/scalalogging/package.scala similarity index 100% rename from src/main/scala/com/typesafe/scalalogging/package.scala rename to scalalogging/src/main/scala/com/typesafe/scalalogging/package.scala diff --git a/src/test/resources/logback.xml b/scalalogging/src/test/resources/logback.xml similarity index 100% rename from src/test/resources/logback.xml rename to scalalogging/src/test/resources/logback.xml diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala b/scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala similarity index 89% rename from src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala rename to scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala index 0082c6d8..76a83612 100644 --- a/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala +++ b/scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala @@ -521,83 +521,23 @@ class LoggerSpec extends AnyWordSpec with Matchers with Varargs with MockitoSuga } } - "Serializing LoggerTakingImplicit" should { - case class CorrelationId(value: String) - implicit val correlationId: CorrelationId = CorrelationId(value = "correlationId") - - implicit case object canLogCorrelationId extends CanLog[CorrelationId] { - def logMessage(originalMsg: String, a: CorrelationId): String = s"${a.value} $originalMsg" - } - - def serialize[A](logger: LoggerTakingImplicit[A]): Array[Byte] = { - val byteArrayStream = new ByteArrayOutputStream - val out = new ObjectOutputStream(byteArrayStream) - - out.writeObject(logger) - out.close() - byteArrayStream.close() - - byteArrayStream.toByteArray - } - - def deserialize[A](array: Array[Byte]): LoggerTakingImplicit[A] = { - val byteArrayStream = new ByteArrayInputStream(array) - val in = new ObjectInputStream(byteArrayStream) - - val logger = in.readObject.asInstanceOf[LoggerTakingImplicit[A]] - in.close() - byteArrayStream.close() - - logger - } - - "be usable after deserialization" in { - val logger = - deserialize[CorrelationId]( - serialize[CorrelationId]( - Logger.takingImplicit[CorrelationId]( - org.slf4j.LoggerFactory.getLogger("test")))) - - logger.trace("Back from deserialization") - } - - "constructed by explicit class and be usable after deserialization" in { - val logger = - deserialize[CorrelationId]( - serialize[CorrelationId]( - Logger.takingImplicit[CorrelationId]( - classOf[LoggerSpec]))) - - logger.trace("Back from deserialization") - } - - "constructed by implicit class tag and be usable after deserialization" in { - val logger = - deserialize[CorrelationId]( - serialize[CorrelationId]( - Logger.takingImplicit[LoggerSpec, CorrelationId])) - - logger.trace("Back from deserialization") - } - } - private def fixture(p: Underlying => Boolean, isEnabled: Boolean) = new LoggerF(p, isEnabled) private class LoggerF(p: Underlying => Boolean, isEnabled: Boolean) { val msg = "msg" val cause = new RuntimeException("cause") val arg1 = "arg1" - val arg2: Integer = Integer.valueOf(1) + val arg2 = Integer.valueOf(1) val arg3 = "arg3" val arg4 = 4 - val arg4ref: AnyRef = arg4.asInstanceOf[AnyRef] + val arg4ref = arg4.asInstanceOf[AnyRef] val arg5 = true - val arg5ref: AnyRef = arg5.asInstanceOf[AnyRef] + val arg5ref = arg5.asInstanceOf[AnyRef] val arg6 = 6L - val arg6ref: AnyRef = arg6.asInstanceOf[AnyRef] + val arg6ref = arg6.asInstanceOf[AnyRef] val arg7 = new Throwable - val arg7ref: AnyRef = arg7.asInstanceOf[AnyRef] - val underlying: Underlying = mock[org.slf4j.Logger] + val arg7ref = arg7.asInstanceOf[AnyRef] + val underlying = mock[org.slf4j.Logger] when(p(underlying)).thenReturn(isEnabled) - val logger: Logger = Logger(underlying) + val logger = Logger(underlying) } } diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala b/scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala similarity index 98% rename from src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala rename to scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala index 53be49a2..fc888558 100644 --- a/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala +++ b/scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerWithMarkerSpec.scala @@ -368,16 +368,14 @@ class LoggerWithMarkerSpec extends AnyWordSpec with Matchers with Varargs with M private def fixture(p: Underlying => Marker => Boolean, isEnabled: Boolean) = new LoggerF(p, isEnabled) private class LoggerF(p: Underlying => Marker => Boolean, isEnabled: Boolean) { - val marker: DummyMarker.type = DummyMarker + val marker = DummyMarker val msg = "msg" val cause = new RuntimeException("cause") val arg1 = "arg1" - val arg2: Integer = Integer.valueOf(1) + val arg2 = Integer.valueOf(1) val arg3 = "arg3" - val underlying: Underlying = mock[org.slf4j.Logger] - + val underlying = mock[org.slf4j.Logger] when(p(underlying)(marker)).thenReturn(isEnabled) - - val logger: Logger = Logger(underlying) + val logger = Logger(underlying) } } diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala b/scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala similarity index 91% rename from src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala rename to scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala index 4500e475..08776829 100644 --- a/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala +++ b/scalalogging/src/test/scala/com/typesafe/scalalogging/LoggerWithTaggedArgsSpec.scala @@ -1,6 +1,5 @@ package com.typesafe.scalalogging -import com.typesafe.scalalogging.tag.@@ import org.slf4j.{ Logger => Underlying } import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec @@ -107,11 +106,11 @@ class LoggerWithTaggedArgsSpec extends AnyWordSpec with Matchers with Varargs wi private def fixture(p: Underlying => Boolean, isEnabled: Boolean = true) = new LoggerF(p, isEnabled) private class LoggerF(p: Underlying => Boolean, isEnabled: Boolean = true) { - val arg1: String @@ Tag = tag.taggedString[Tag]("arg1") - val arg2: Integer @@ Tag = tag.taggedInteger[Tag](Integer.valueOf(1)) - val arg3: Boolean @@ Boolean = tag.taggedBoolean[Boolean](true) - val underlying: Underlying = mock[org.slf4j.Logger] + val arg1 = tag.taggedString[Tag]("arg1") + val arg2 = tag.taggedInteger[Tag](Integer.valueOf(1)) + val arg3 = tag.taggedBoolean[Boolean](true) + val underlying = mock[org.slf4j.Logger] when(p(underlying)).thenReturn(isEnabled) - val logger: Logger = Logger(underlying) + val logger = Logger(underlying) } } diff --git a/src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala b/scalalogging2/src/main/scala/com/typesafe/scalalogging/LoggerMacro2.scala similarity index 98% rename from src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala rename to scalalogging2/src/main/scala/com/typesafe/scalalogging/LoggerMacro2.scala index dbef6b28..ef79168f 100644 --- a/src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala +++ b/scalalogging2/src/main/scala/com/typesafe/scalalogging/LoggerMacro2.scala @@ -1,11 +1,11 @@ package com.typesafe.scalalogging -import org.slf4j.Marker +import org.slf4j.{ Marker } import scala.reflect.macros.blackbox -private[scalalogging] object LoggerMacro { +private[scalalogging] object LoggerMacro2 { - type LoggerContext = blackbox.Context { type PrefixType = Logger } + type LoggerContext = blackbox.Context // Error diff --git a/scalalogging3/src/.editorconfig b/scalalogging3/src/.editorconfig new file mode 100644 index 00000000..c1322dc7 --- /dev/null +++ b/scalalogging3/src/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala b/scalalogging3/src/main/scala/com/typesafe/scalalogging/LoggerMacro3.scala similarity index 99% rename from src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala rename to scalalogging3/src/main/scala/com/typesafe/scalalogging/LoggerMacro3.scala index 2013f485..0453bf0c 100644 --- a/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala +++ b/scalalogging3/src/main/scala/com/typesafe/scalalogging/LoggerMacro3.scala @@ -4,7 +4,7 @@ import org.slf4j.Marker import scala.quoted.* import org.slf4j.{ Logger as Underlying } -private[scalalogging] object LoggerMacro { +private[scalalogging] object LoggerMacro3 { // 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 f1bfcb84..00000000 --- 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 070a6973..00000000 --- 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 diff --git a/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala b/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala deleted file mode 100644 index dcce88cb..00000000 --- a/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala +++ /dev/null @@ -1,439 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.Marker -import scala.reflect.macros.blackbox - -private[scalalogging] object LoggerTakingImplicitMacro { - - type LoggerContext[A] = blackbox.Context { type PrefixType = LoggerTakingImplicit[A] } - - // Error - - def errorMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def errorMessageCause[A](c: LoggerContext[A])(message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def errorMessageArgs[A](c: LoggerContext[A])(message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def errorMessageMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def errorMessageCauseMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def errorMessageArgsMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def errorCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($body)) - $canLogEv.afterLog($a) - }""" - } - - // Warn - - def warnMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def warnMessageCause[A](c: LoggerContext[A])(message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def warnMessageArgs[A](c: LoggerContext[A])(message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def warnMessageMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def warnMessageCauseMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def warnMessageArgsMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def warnCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($body)) - $canLogEv.afterLog($a) - }""" - } - - // Info - - def infoMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def infoMessageCause[A](c: LoggerContext[A])(message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def infoMessageArgs[A](c: LoggerContext[A])(message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def infoMessageMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def infoMessageCauseMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def infoMessageArgsMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def infoCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($body)) - $canLogEv.afterLog($a) - }""" - } - - // Debug - - def debugMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def debugMessageCause[A](c: LoggerContext[A])(message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def debugMessageArgs[A](c: LoggerContext[A])(message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def debugMessageMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def debugMessageCauseMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def debugMessageArgsMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def debugCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($body)) - $canLogEv.afterLog($a) - }""" - } - - // Trace - - def traceMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def traceMessageCause[A](c: LoggerContext[A])(message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def traceMessageArgs[A](c: LoggerContext[A])(message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def traceMessageMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }""" - } - - def traceMessageCauseMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }""" - } - - def traceMessageArgsMarker[A](c: LoggerContext[A])(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*)(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - if (args.length == 2) { - q"""if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a), List(${args(0)}, ${args(1)}): _*) - $canLogEv.afterLog($a) - }""" - } else { - q"""if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a), ..$args) - $canLogEv.afterLog($a) - }""" - } - } - - def traceCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = { - import c.universe._ - val underlying = q"${c.prefix}.underlying" - val canLogEv = q"${c.prefix}.canLogEv" - q"""if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($body)) - $canLogEv.afterLog($a) - }""" - } -} diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala b/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala deleted file mode 100644 index 9d328263..00000000 --- a/src/main/scala-3/com/typesafe/scalalogging/LoggerImpl.scala +++ /dev/null @@ -1,57 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.{Marker, Logger as Underlying } - -trait LoggerImpl { - def underlying: Underlying - - - // Error - inline def error(inline message: String): Unit = ${LoggerMacro.errorMessage('underlying, 'message)} - inline def error(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.errorMessageCause('underlying, 'message, 'cause)} - inline def error(inline message: String, inline args: Any*): Unit = ${LoggerMacro.errorMessageArgs('underlying, 'message, 'args)} - inline def error(inline marker: Marker, inline message: String): Unit = ${LoggerMacro.errorMessageMarker('underlying, 'marker, 'message)} - inline def error(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.errorMessageCauseMarker('underlying, 'marker, 'message, 'cause)} - inline def error(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro.errorMessageArgsMarker('underlying, 'marker, 'message, 'args)} - inline def whenErrorEnabled(inline body: Unit): Unit = ${LoggerMacro.errorCode('underlying, 'body)} - - - // Warn - inline def warn(inline message: String): Unit = ${LoggerMacro.warnMessage('underlying, 'message)} - inline def warn(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.warnMessageCause('underlying, 'message, 'cause)} - inline def warn(inline message: String, inline args: Any*): Unit = ${LoggerMacro.warnMessageArgs('underlying, 'message, 'args)} - inline def warn(inline marker: Marker, inline message: String): Unit = ${LoggerMacro.warnMessageMarker('underlying, 'marker, 'message)} - inline def warn(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.warnMessageCauseMarker('underlying, 'marker, 'message, 'cause)} - inline def warn(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro.warnMessageArgsMarker('underlying, 'marker, 'message, 'args)} - inline def whenWarnEnabled(inline body: Unit): Unit = ${LoggerMacro.warnCode('underlying, 'body)} - - - // Info - inline def info(inline message: String): Unit = ${LoggerMacro.infoMessage('underlying, 'message)} - inline def info(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.infoMessageCause('underlying, 'message, 'cause)} - inline def info(inline message: String, inline args: Any*): Unit = ${LoggerMacro.infoMessageArgs('underlying, 'message, 'args)} - inline def info(inline marker: Marker, inline message: String): Unit = ${LoggerMacro.infoMessageMarker('underlying, 'marker, 'message)} - inline def info(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.infoMessageCauseMarker('underlying, 'marker, 'message, 'cause)} - inline def info(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro.infoMessageArgsMarker('underlying, 'marker, 'message, 'args)} - inline def whenInfoEnabled(inline body: Unit): Unit = ${LoggerMacro.infoCode('underlying, 'body)} - - - // Debug - inline def debug(inline message: String): Unit = ${LoggerMacro.debugMessage('underlying, 'message)} - inline def debug(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.debugMessageCause('underlying, 'message, 'cause)} - inline def debug(inline message: String, inline args: Any*): Unit = ${LoggerMacro.debugMessageArgs('underlying, 'message, 'args)} - inline def debug(inline marker: Marker, inline message: String): Unit = ${LoggerMacro.debugMessageMarker('underlying, 'marker, 'message)} - inline def debug(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.debugMessageCauseMarker('underlying, 'marker, 'message, 'cause)} - inline def debug(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro.debugMessageArgsMarker('underlying, 'marker, 'message, 'args)} - inline def whenDebugEnabled(inline body: Unit): Unit = ${LoggerMacro.debugCode('underlying, 'body)} - - - // Trace - inline def trace(inline message: String): Unit = ${LoggerMacro.traceMessage('underlying, 'message)} - inline def trace(inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.traceMessageCause('underlying, 'message, 'cause)} - inline def trace(inline message: String, inline args: Any*): Unit = ${LoggerMacro.traceMessageArgs('underlying, 'message, 'args)} - inline def trace(inline marker: Marker, inline message: String): Unit = ${LoggerMacro.traceMessageMarker('underlying, 'marker, 'message)} - 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)} -} diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala b/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala deleted file mode 100644 index 5e99eeca..00000000 --- a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala +++ /dev/null @@ -1,122 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.{Marker, Logger as Underlying } - -trait LoggerTakingImplicitImpl[A] { - def underlying: Underlying - implicit val canLogEv: CanLog[A] - - - // Error - - inline def error(inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.errorMessage('underlying, 'canLogEv, 'message)('a)} - - inline def error(inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.errorMessageCause('underlying, 'canLogEv, 'message, 'cause)('a)} - - inline def error(inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.errorMessageArgs('underlying, 'canLogEv, 'message, 'args)('a)} - - inline def error(inline marker: Marker, inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.errorMessageMarker('underlying, 'canLogEv, 'marker, 'message)('a)} - - inline def error(inline marker: Marker, inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.errorMessageCauseMarker('underlying, 'canLogEv, 'marker, 'message, 'cause)('a)} - - inline def error(inline marker: Marker, inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.errorMessageArgsMarker('underlying, 'canLogEv, 'marker,'message, 'args)('a)} - - inline def whenErrorEnabled(inline body: Unit)(implicit inline a: A): Unit = ${LoggerTakingImplicitMacro.errorCode('underlying, 'canLogEv, 'body)('a)} - - // Warn - - inline def warn(inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.warnMessage('underlying, 'canLogEv, 'message)('a)} - - inline def warn(inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.warnMessageCause('underlying, 'canLogEv, 'message, 'cause)('a)} - - inline def warn(inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.warnMessageArgs('underlying, 'canLogEv, 'message, 'args)('a)} - - inline def warn(inline marker: Marker, inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.warnMessageMarker('underlying, 'canLogEv, 'marker, 'message)('a)} - - inline def warn(inline marker: Marker, inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.warnMessageCauseMarker('underlying, 'canLogEv, 'marker, 'message, 'cause)('a)} - - inline def warn(inline marker: Marker, inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.warnMessageArgsMarker('underlying, 'canLogEv, 'marker,'message, 'args)('a)} - - inline def whenWarnEnabled(inline body: Unit)(implicit inline a: A): Unit = ${LoggerTakingImplicitMacro.warnCode('underlying, 'canLogEv, 'body)('a)} - - - - // Info - - inline def info(inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.infoMessage('underlying, 'canLogEv, 'message)('a)} - - inline def info(inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.infoMessageCause('underlying, 'canLogEv, 'message, 'cause)('a)} - - inline def info(inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.infoMessageArgs('underlying, 'canLogEv, 'message, 'args)('a)} - - inline def info(inline marker: Marker, inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.infoMessageMarker('underlying, 'canLogEv, 'marker, 'message)('a)} - - inline def info(inline marker: Marker, inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.infoMessageCauseMarker('underlying, 'canLogEv, 'marker, 'message, 'cause)('a)} - - inline def info(inline marker: Marker, inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.infoMessageArgsMarker('underlying, 'canLogEv, 'marker,'message, 'args)('a)} - - inline def whenInfoEnabled(inline body: Unit)(implicit inline a: A): Unit = ${LoggerTakingImplicitMacro.infoCode('underlying, 'canLogEv, 'body)('a)} - - - // Debug - - inline def debug(inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.debugMessage('underlying, 'canLogEv, 'message)('a)} - - inline def debug(inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.debugMessageCause('underlying, 'canLogEv, 'message, 'cause)('a)} - - inline def debug(inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.debugMessageArgs('underlying, 'canLogEv, 'message, 'args)('a)} - - inline def debug(inline marker: Marker, inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.debugMessageMarker('underlying, 'canLogEv, 'marker, 'message)('a)} - - inline def debug(inline marker: Marker, inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.debugMessageCauseMarker('underlying, 'canLogEv, 'marker, 'message, 'cause)('a)} - - inline def debug(inline marker: Marker, inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.debugMessageArgsMarker('underlying, 'canLogEv, 'marker,'message, 'args)('a)} - - inline def whenDebugEnabled(inline body: Unit)(implicit inline a: A): Unit = ${LoggerTakingImplicitMacro.debugCode('underlying, 'canLogEv, 'body)('a)} - - // Trace - - inline def trace(inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.traceMessage('underlying, 'canLogEv, 'message)('a)} - - inline def trace(inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.traceMessageCause('underlying, 'canLogEv, 'message, 'cause)('a)} - - inline def trace(inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.traceMessageArgs('underlying, 'canLogEv, 'message, 'args)('a)} - - inline def trace(inline marker: Marker, inline message: String)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.traceMessageMarker('underlying, 'canLogEv, 'marker, 'message)('a)} - - inline def trace(inline marker: Marker, inline message: String, inline cause: Throwable)(implicit inline a: A): Unit = - ${LoggerTakingImplicitMacro.traceMessageCauseMarker('underlying, 'canLogEv, 'marker, 'message, 'cause)('a)} - - inline def trace(inline marker: Marker, inline message: String, inline args: Any*)(implicit inline a: A): Unit = - ${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)} -} diff --git a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala b/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala deleted file mode 100644 index 31bff705..00000000 --- a/src/main/scala-3/com/typesafe/scalalogging/LoggerTakingImplicitMacro.scala +++ /dev/null @@ -1,311 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.{ Marker, Logger => Underlying } - -import scala.quoted.* - -private[scalalogging] object LoggerTakingImplicitMacro { - - // Error - - def errorMessage[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if($underlying.isErrorEnabled){ - $underlying.error($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def errorMessageCause[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def errorMessageArgs[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isErrorEnabled) { - $underlying.error($canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def errorMessageMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def errorMessageCauseMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def errorMessageArgsMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isErrorEnabled($marker)) { - $underlying.error($marker, $canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def errorCode[A:Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], body: Expr[Unit])(a: Expr[A])(using Quotes) = - '{if ($underlying.isErrorEnabled) { - $body - $canLogEv.afterLog($a) - }} - - // Warn - - def warnMessage[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if($underlying.isWarnEnabled){ - $underlying.warn($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def warnMessageCause[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def warnMessageArgs[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isWarnEnabled) { - $underlying.warn($canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def warnMessageMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def warnMessageCauseMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def warnMessageArgsMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isWarnEnabled($marker)) { - $underlying.warn($marker, $canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def warnCode[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], body: Expr[Unit])(a: Expr[A])(using Quotes) = - '{ if ($underlying.isWarnEnabled) { - $body - $canLogEv.afterLog($a) - }} - - - // Info - - def infoMessage[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if($underlying.isInfoEnabled){ - $underlying.info($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def infoMessageCause[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def infoMessageArgs[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isInfoEnabled) { - $underlying.info($canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def infoMessageMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def infoMessageCauseMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def infoMessageArgsMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isInfoEnabled($marker)) { - $underlying.info($marker, $canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def infoCode[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], body: Expr[Unit])(a: Expr[A])(using Quotes) = - '{ if ($underlying.isInfoEnabled) { - $body - $canLogEv.afterLog($a) - }} - - - // Debug - - def debugMessage[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if($underlying.isDebugEnabled){ - $underlying.debug($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def debugMessageCause[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def debugMessageArgs[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isDebugEnabled) { - $underlying.debug($canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def debugMessageMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def debugMessageCauseMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def debugMessageArgsMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isDebugEnabled($marker)) { - $underlying.debug($marker, $canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def debugCode[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], body: Expr[Unit])(a: Expr[A])(using Quotes) = - '{ if ($underlying.isDebugEnabled) { - $body - $canLogEv.afterLog($a) - }} - - - // Trace - - def traceMessage[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if($underlying.isTraceEnabled){ - $underlying.trace($canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def traceMessageCause[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def traceMessageArgs[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isTraceEnabled) { - $underlying.trace($canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def traceMessageMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a)) - $canLogEv.afterLog($a) - }} - - def traceMessageCauseMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], cause: Expr[Throwable])(a: Expr[A])(using Quotes): Expr[Unit] = - '{if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a), $cause) - $canLogEv.afterLog($a) - }} - - def traceMessageArgsMarker[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], marker: Expr[Marker], message: Expr[String], args: Expr[Seq[Any]])(a: Expr[A])(using Quotes): Expr[Unit] = { - val formatedArgs = LoggerMacro.formatArgs(args) - if (formatedArgs.length == 1) - '{if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a), ${formatedArgs.head}) - $canLogEv.afterLog($a) - }} - else - '{if ($underlying.isTraceEnabled($marker)) { - $underlying.trace($marker, $canLogEv.logMessage($message, $a), ${Expr.ofSeq(formatedArgs)}*) - $canLogEv.afterLog($a) - }} - } - - def traceCode[A: Type](underlying: Expr[Underlying], canLogEv: Expr[CanLog[A]], body: Expr[Unit])(a: Expr[A])(using Quotes) = - '{ if ($underlying.isTraceEnabled) { - $body - $canLogEv.afterLog($a) - }} -} \ No newline at end of file diff --git a/src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala b/src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala deleted file mode 100644 index 5f7a0a34..00000000 --- a/src/main/scala/com/typesafe/scalalogging/LoggerTakingImplicit.scala +++ /dev/null @@ -1,14 +0,0 @@ -package com.typesafe.scalalogging - -import org.slf4j.{ Logger => Underlying } - -trait CanLog[A] { - def logMessage(originalMsg: String, context: A): String - def afterLog(context: A): Unit = { - val _ = context - } - def getContext()(implicit context: A): A = context -} - -@SerialVersionUID(957385465L) -class LoggerTakingImplicit[A] private[scalalogging] (val underlying: Underlying)(implicit val canLogEv: CanLog[A]) extends LoggerTakingImplicitImpl[A] with Serializable \ No newline at end of file diff --git a/src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala b/src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala deleted file mode 100644 index 549468b0..00000000 --- a/src/test/scala/com/typesafe/scalalogging/LoggerTakingImplicitSpec.scala +++ /dev/null @@ -1,403 +0,0 @@ -package com.typesafe.scalalogging - -import org.mockito.ArgumentMatchers._ -import org.mockito.Mockito._ -import org.scalatestplus.mockito.MockitoSugar -import org.slf4j.{ Logger => Underlying } -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AnyWordSpec - -class LoggerTakingImplicitSpec extends AnyWordSpec with Matchers with Varargs with MockitoSugar { - - case class CorrelationId(value: String) - - // Error - - "Calling error with a message" should { - - "call the underlying logger's error method if the error level is enabled" in { - val f = fixture(_.isErrorEnabled, isEnabled = true) - import f._ - logger.error(msg) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).error(logMsg) - } - - "not call the underlying logger's error method if the error level is not enabled" in { - val f = fixture(_.isErrorEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.error(msg) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).error(any[String]) - } - } - - "Calling error with a message and cause" should { - - "call the underlying logger's error method if the error level is enabled" in { - val f = fixture(_.isErrorEnabled, isEnabled = true) - import f._ - logger.error(msg, cause) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).error(logMsg, cause) - } - - "not call the underlying logger's error method if the error level is not enabled" in { - val f = fixture(_.isErrorEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.error(msg, cause) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).error(any[String], any[Object]) - } - } - - "Calling error with a message and parameters" should { - - "call the underlying logger's error method if the error level is enabled" in { - val f = fixture(_.isErrorEnabled, isEnabled = true) - import f._ - logger.error(msg, arg1) - verify(underlying).error(logMsg, arg1) - logger.error(msg, arg1, arg2) - verify(underlying).error(logMsg, forceVarargs(arg1, arg2): _*) - logger.error(msg, arg1, arg2, arg3) - verify(underlying).error(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, times(3)).logMessage(msg, correlationId) - verify(canLogCorrelationId, times(3)).afterLog(correlationId) - } - - "not call the underlying logger's error method if the error level is not enabled" in { - val f = fixture(_.isErrorEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.error(msg, arg1) - verify(underlying, never).error(logMsg, arg1) - logger.error(msg, arg1, arg2) - verify(underlying, never).error(logMsg, forceVarargs(arg1, arg2): _*) - logger.error(msg, arg1, arg2, arg3) - verify(underlying, never).error(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - } - } - - // Warn - - "Calling warn with a message" should { - - "call the underlying logger's warn method if the warn level is enabled" in { - val f = fixture(_.isWarnEnabled, isEnabled = true) - import f._ - logger.warn(msg) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).warn(logMsg) - } - - "not call the underlying logger's warn method if the warn level is not enabled" in { - val f = fixture(_.isWarnEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.warn(msg) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).warn(any[String]) - } - } - - "Calling warn with a message and cause" should { - - "call the underlying logger's warn method if the warn level is enabled" in { - val f = fixture(_.isWarnEnabled, isEnabled = true) - import f._ - logger.warn(msg, cause) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).warn(logMsg, cause) - } - - "not call the underlying logger's warn method if the warn level is not enabled" in { - val f = fixture(_.isWarnEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.warn(msg, cause) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).warn(any[String], any[Object]) - } - } - - "Calling warn with a message and parameters" should { - - "call the underlying logger's warn method if the warn level is enabled" in { - val f = fixture(_.isWarnEnabled, isEnabled = true) - import f._ - logger.warn(msg, arg1) - verify(underlying).warn(logMsg, arg1) - logger.warn(msg, arg1, arg2) - verify(underlying).warn(logMsg, forceVarargs(arg1, arg2): _*) - logger.warn(msg, arg1, arg2, arg3) - verify(underlying).warn(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, times(3)).logMessage(msg, correlationId) - verify(canLogCorrelationId, times(3)).afterLog(correlationId) - } - - "not call the underlying logger's warn method if the warn level is not enabled" in { - val f = fixture(_.isWarnEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.warn(msg, arg1) - verify(underlying, never).warn(logMsg, arg1) - logger.warn(msg, arg1, arg2) - verify(underlying, never).warn(logMsg, forceVarargs(arg1, arg2): _*) - logger.warn(msg, arg1, arg2, arg3) - verify(underlying, never).warn(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - } - } - - // Info - - "Calling info with a message" should { - - "call the underlying logger's info method if the info level is enabled" in { - val f = fixture(_.isInfoEnabled, isEnabled = true) - import f._ - logger.info(msg) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).info(logMsg) - } - - "not call the underlying logger's info method if the info level is not enabled" in { - val f = fixture(_.isInfoEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.info(msg) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).info(any[String]) - } - } - - "Calling info with a message and cause" should { - - "call the underlying logger's info method if the info level is enabled" in { - val f = fixture(_.isInfoEnabled, isEnabled = true) - import f._ - logger.info(msg, cause) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).info(logMsg, cause) - } - - "not call the underlying logger's info method if the info level is not enabled" in { - val f = fixture(_.isInfoEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.info(msg, cause) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).info(any[String], any[Object]) - } - } - - "Calling info with a message and parameters" should { - - "call the underlying logger's info method if the info level is enabled" in { - val f = fixture(_.isInfoEnabled, isEnabled = true) - import f._ - logger.info(msg, arg1) - verify(underlying).info(logMsg, arg1) - logger.info(msg, arg1, arg2) - verify(underlying).info(logMsg, forceVarargs(arg1, arg2): _*) - logger.info(msg, arg1, arg2, arg3) - verify(underlying).info(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, times(3)).logMessage(msg, correlationId) - verify(canLogCorrelationId, times(3)).afterLog(correlationId) - } - - "not call the underlying logger's info method if the info level is not enabled" in { - val f = fixture(_.isInfoEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.info(msg, arg1) - verify(underlying, never).info(logMsg, arg1) - logger.info(msg, arg1, arg2) - verify(underlying, never).info(logMsg, forceVarargs(arg1, arg2): _*) - logger.info(msg, arg1, arg2, arg3) - verify(underlying, never).info(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - } - } - - // Debug - - "Calling debug with a message" should { - - "call the underlying logger's debug method if the debug level is enabled" in { - val f = fixture(_.isDebugEnabled, isEnabled = true) - import f._ - logger.debug(msg) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).debug(logMsg) - } - - "not call the underlying logger's debug method if the debug level is not enabled" in { - val f = fixture(_.isDebugEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.debug(msg) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).debug(any[String]) - } - } - - "Calling debug with a message and cause" should { - - "call the underlying logger's debug method if the debug level is enabled" in { - val f = fixture(_.isDebugEnabled, isEnabled = true) - import f._ - logger.debug(msg, cause) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).debug(logMsg, cause) - } - - "not call the underlying logger's debug method if the debug level is not enabled" in { - val f = fixture(_.isDebugEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.debug(msg, cause) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).debug(any[String], any[Object]) - } - } - - "Calling debug with a message and parameters" should { - - "call the underlying logger's debug method if the debug level is enabled" in { - val f = fixture(_.isDebugEnabled, isEnabled = true) - import f._ - logger.debug(msg, arg1) - verify(underlying).debug(logMsg, arg1) - logger.debug(msg, arg1, arg2) - verify(underlying).debug(logMsg, forceVarargs(arg1, arg2): _*) - logger.debug(msg, arg1, arg2, arg3) - verify(underlying).debug(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, times(3)).logMessage(msg, correlationId) - verify(canLogCorrelationId, times(3)).afterLog(correlationId) - } - - "not call the underlying logger's debug method if the debug level is not enabled" in { - val f = fixture(_.isDebugEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.debug(msg, arg1) - verify(underlying, never).debug(logMsg, arg1) - logger.debug(msg, arg1, arg2) - verify(underlying, never).debug(logMsg, forceVarargs(arg1, arg2): _*) - logger.debug(msg, arg1, arg2, arg3) - verify(underlying, never).debug(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - } - } - - // Trace - - "Calling trace with a message" should { - - "call the underlying logger's trace method if the trace level is enabled" in { - val f = fixture(_.isTraceEnabled, isEnabled = true) - import f._ - logger.trace(msg) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).trace(logMsg) - } - - "not call the underlying logger's trace method if the trace level is not enabled" in { - val f = fixture(_.isTraceEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.trace(msg) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).trace(any[String]) - } - } - - "Calling trace with a message and cause" should { - - "call the underlying logger's trace method if the trace level is enabled" in { - val f = fixture(_.isTraceEnabled, isEnabled = true) - import f._ - logger.trace(msg, cause) - verify(canLogCorrelationId).logMessage(msg, correlationId) - verify(canLogCorrelationId).afterLog(correlationId) - verify(underlying).trace(logMsg, cause) - } - - "not call the underlying logger's trace method if the trace level is not enabled" in { - val f = fixture(_.isTraceEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.trace(msg, cause) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - verify(underlying, never).trace(any[String], any[Object]) - } - } - - "Calling trace with a message and parameters" should { - - "call the underlying logger's trace method if the trace level is enabled" in { - val f = fixture(_.isTraceEnabled, isEnabled = true) - import f._ - logger.trace(msg, arg1) - verify(underlying).trace(logMsg, arg1) - logger.trace(msg, arg1, arg2) - verify(underlying).trace(logMsg, forceVarargs(arg1, arg2): _*) - logger.trace(msg, arg1, arg2, arg3) - verify(underlying).trace(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, times(3)).logMessage(msg, correlationId) - verify(canLogCorrelationId, times(3)).afterLog(correlationId) - } - - "not call the underlying logger's trace method if the trace level is not enabled" in { - val f = fixture(_.isTraceEnabled, isEnabled = false, stubCanLog = false) - import f._ - logger.trace(msg, arg1) - verify(underlying, never).trace(logMsg, arg1) - logger.trace(msg, arg1, arg2) - verify(underlying, never).trace(logMsg, forceVarargs(arg1, arg2): _*) - logger.trace(msg, arg1, arg2, arg3) - verify(underlying, never).trace(logMsg, arg1, arg2, arg3) - verify(canLogCorrelationId, never).logMessage(any[String], any[CorrelationId]) - verify(canLogCorrelationId, never).afterLog(any[CorrelationId]) - } - } - - "Calling getContext" should { - "call getContext on the underlying logger's CanLog" in { - val f = fixture(_.isErrorEnabled, isEnabled = true) - import f._ - logger.canLogEv.getContext() - verify(canLogCorrelationId).getContext() - } - } - - private def fixture(p: Underlying => Boolean, isEnabled: Boolean, stubCanLog: Boolean = true) = new LoggerF(p, isEnabled, stubCanLog) - private class LoggerF(p: Underlying => Boolean, isEnabled: Boolean, stubCanLog: Boolean = true) { - implicit val correlationId: CorrelationId = CorrelationId("corrId") - implicit val canLogCorrelationId: CanLog[CorrelationId] = mock[CanLog[CorrelationId]] - val msg = "msg" - val cause = new RuntimeException("cause") - val arg1 = "arg1" - val arg2: Integer = Integer.valueOf(1) - val arg3 = "arg3" - val logMsg = "corrId - msg" - val underlying: Underlying = mock[org.slf4j.Logger] - when(p(underlying)).thenReturn(isEnabled) - if (stubCanLog) when(canLogCorrelationId.logMessage(any[String], any[CorrelationId])).thenReturn(logMsg) - val logger: LoggerTakingImplicit[CorrelationId] = Logger.takingImplicit[CorrelationId](underlying) - } -} From 9752b28289c338b0cc61fc3f84b93c66e3c3ad3c Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 6 Apr 2022 14:17:08 -0600 Subject: [PATCH 2/2] Don't run tests against scala 2.11 or scala 2.12 Definitely don't merge this into the upstream repo! --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22d1d494..c266f43d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: java: [8, 11, 17] - scala: [2.11.12, 2.12.15, 2.13.8, 3.0.2] + scala: [2.13.8, 3.0.2] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2