-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
define the scala 2 macros in the scala 3 module #415
Open
johnduffell
wants to merge
2
commits into
lightbend-labs:main
Choose a base branch
from
johnduffell:jd-cross-macros
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,77 @@ | ||
// basics | ||
|
||
name := "scala-logging" | ||
crossScalaVersions := Seq("3.3.1", "2.11.12", "2.12.18", "2.13.12") | ||
scalaVersion := crossScalaVersions.value.head | ||
ThisBuild / versionScheme := Some("early-semver") | ||
scalacOptions ++= Seq( | ||
"-unchecked", | ||
"-deprecation", | ||
"-language:_", | ||
"-encoding", "UTF-8", | ||
"-Ywarn-unused" | ||
) | ||
incOptions := incOptions.value.withLogRecompileOnMacro(false) | ||
val scala213 = "2.13.12" | ||
val scala3 = "3.4.0" | ||
val scala2 = Seq("2.11.12", "2.12.18", scala213) | ||
val isScala3 = Def.setting { | ||
CrossVersion.partialVersion(scalaVersion.value).exists(_._1 != 2) | ||
} | ||
libraryDependencies ++= Dependencies.scalaLogging(scalaVersion.value, isScala3.value) | ||
initialCommands := """|import com.typesafe.scalalogging._ | ||
|import org.slf4j.{ Logger => Underlying, _ }""".stripMargin | ||
|
||
// OSGi | ||
|
||
import com.typesafe.sbt.osgi.SbtOsgi | ||
enablePlugins(SbtOsgi) | ||
osgiSettings | ||
OsgiKeys.bundleSymbolicName := "com.typesafe.scala-logging" | ||
OsgiKeys.privatePackage := Seq() | ||
OsgiKeys.exportPackage := Seq("com.typesafe.scalalogging*") | ||
|
||
// publishing | ||
|
||
organization := "com.typesafe.scala-logging" | ||
sonatypeProfileName := "com.typesafe" | ||
licenses := Seq("Apache 2.0 License" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")) | ||
homepage := Some(url("https://github.com/lightbend/scala-logging")) | ||
Test / publishArtifact := false | ||
pomIncludeRepository := (_ => false) | ||
scmInfo := Some( | ||
ScmInfo(url("https://github.com/lightbend/scala-logging"), "scm:git:[email protected]:lightbend/scala-logging.git") | ||
) | ||
developers := List( | ||
Developer( | ||
id = "hseeberger", | ||
name = "Heiko Seeberger", | ||
email = "", | ||
url = url("http://heikoseeberger.de") | ||
), | ||
Developer( | ||
id = "analytically", | ||
name = "Mathias Bogaert", | ||
email = "", | ||
url = url("http://twitter.com/analytically") | ||
import sbt.url | ||
|
||
lazy val root = (project in file(".")).aggregate(main, scala2macros) | ||
|
||
lazy val main = (project in file("main")) | ||
.enablePlugins(SbtOsgi) | ||
.settings( | ||
name := "scala-logging", | ||
crossScalaVersions := Seq(scala3) ++ scala2, | ||
scalaVersion := crossScalaVersions.value.head, | ||
ThisBuild / versionScheme := Some("early-semver"), | ||
scalacOptions ++= Seq( | ||
"-unchecked", | ||
"-deprecation", | ||
"-language:_", | ||
"-encoding", "UTF-8", | ||
"-Ywarn-unused" | ||
), | ||
incOptions := incOptions.value.withLogRecompileOnMacro(false), | ||
libraryDependencies ++= Dependencies.scalaLogging(scalaVersion.value, isScala3.value), | ||
initialCommands := """|import com.typesafe.scalalogging._ | ||
|import org.slf4j.{ Logger => Underlying, _ }""".stripMargin | ||
).settings( | ||
// OSGi | ||
|
||
osgiSettings | ||
).settings( | ||
OsgiKeys.bundleSymbolicName := "com.typesafe.scala-logging", | ||
OsgiKeys.privatePackage := Seq(), | ||
OsgiKeys.exportPackage := Seq("com.typesafe.scalalogging*"), | ||
|
||
// publishing | ||
|
||
organization := "com.typesafe.scala-logging", | ||
sonatypeProfileName := "com.typesafe", | ||
licenses := Seq("Apache 2.0 License" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")), | ||
homepage := Some(url("https://github.com/lightbend/scala-logging")), | ||
Test / publishArtifact := false, | ||
pomIncludeRepository := (_ => false), | ||
scmInfo := Some( | ||
ScmInfo(url("https://github.com/lightbend/scala-logging"), "scm:git:[email protected]:lightbend/scala-logging.git") | ||
), | ||
developers := List( | ||
Developer( | ||
id = "hseeberger", | ||
name = "Heiko Seeberger", | ||
email = "", | ||
url = url("http://heikoseeberger.de") | ||
), | ||
Developer( | ||
id = "analytically", | ||
name = "Mathias Bogaert", | ||
email = "", | ||
url = url("http://twitter.com/analytically") | ||
) | ||
) | ||
|
||
) | ||
.dependsOn(scala2macros) | ||
|
||
lazy val scala2macros = project | ||
.settings( | ||
name := "scala2macros", | ||
scalaVersion := scala213, | ||
crossScalaVersions := scala2, | ||
libraryDependencies ++= Dependencies.scalaLogging(scalaVersion.value, false), | ||
) | ||
) |
File renamed without changes.
85 changes: 85 additions & 0 deletions
85
main/src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.typesafe.scalalogging | ||
|
||
import org.slf4j.Marker | ||
class LoggerImpl { | ||
|
||
// Error | ||
|
||
def error(message: String): Unit = macro Scala2LoggerMacro.errorMessage | ||
|
||
def error(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCause | ||
|
||
def error(message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgs | ||
|
||
def error(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.errorMessageMarker | ||
|
||
def error(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCauseMarker | ||
|
||
def error(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgsMarker | ||
|
||
def whenErrorEnabled(body: Unit): Unit = macro Scala2LoggerMacro.errorCode | ||
|
||
// Warn | ||
|
||
def warn(message: String): Unit = macro Scala2LoggerMacro.warnMessage | ||
|
||
def warn(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCause | ||
|
||
def warn(message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgs | ||
|
||
def warn(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.warnMessageMarker | ||
|
||
def warn(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCauseMarker | ||
|
||
def warn(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgsMarker | ||
|
||
def whenWarnEnabled(body: Unit): Unit = macro Scala2LoggerMacro.warnCode | ||
|
||
// Info | ||
|
||
def info(message: String): Unit = macro Scala2LoggerMacro.infoMessage | ||
|
||
def info(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCause | ||
|
||
def info(message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgs | ||
|
||
def info(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.infoMessageMarker | ||
|
||
def info(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCauseMarker | ||
|
||
def info(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgsMarker | ||
|
||
def whenInfoEnabled(body: Unit): Unit = macro Scala2LoggerMacro.infoCode | ||
|
||
// Debug | ||
|
||
def debug(message: String): Unit = macro Scala2LoggerMacro.debugMessage | ||
|
||
def debug(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCause | ||
|
||
def debug(message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgs | ||
|
||
def debug(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.debugMessageMarker | ||
|
||
def debug(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCauseMarker | ||
|
||
def debug(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgsMarker | ||
|
||
def whenDebugEnabled(body: Unit): Unit = macro Scala2LoggerMacro.debugCode | ||
|
||
// Trace | ||
|
||
def trace(message: String): Unit = macro Scala2LoggerMacro.traceMessage | ||
|
||
def trace(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCause | ||
|
||
def trace(message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgs | ||
|
||
def trace(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.traceMessageMarker | ||
|
||
def trace(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCauseMarker | ||
|
||
def trace(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgsMarker | ||
|
||
def whenTraceEnabled(body: Unit): Unit = macro Scala2LoggerMacro.traceCode | ||
} |
86 changes: 86 additions & 0 deletions
86
main/src/main/scala-2/com/typesafe/scalalogging/LoggerTakingImplicitImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.typesafe.scalalogging | ||
|
||
import org.slf4j.Marker | ||
|
||
class LoggerTakingImplicitImpl[A] private[scalalogging] { | ||
|
||
// Error | ||
|
||
def error(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessage[A] | ||
|
||
def error(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageCause[A] | ||
|
||
def error(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageArgs[A] | ||
|
||
def error(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageMarker[A] | ||
|
||
def error(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageCauseMarker[A] | ||
|
||
def error(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorMessageArgsMarker[A] | ||
|
||
def whenErrorEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.errorCode[A] | ||
|
||
// Warn | ||
|
||
def warn(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessage[A] | ||
|
||
def warn(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageCause[A] | ||
|
||
def warn(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageArgs[A] | ||
|
||
def warn(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageMarker[A] | ||
|
||
def warn(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageCauseMarker[A] | ||
|
||
def warn(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnMessageArgsMarker[A] | ||
|
||
def whenWarnEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.warnCode[A] | ||
|
||
// Info | ||
|
||
def info(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessage[A] | ||
|
||
def info(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageCause[A] | ||
|
||
def info(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageArgs[A] | ||
|
||
def info(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageMarker[A] | ||
|
||
def info(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageCauseMarker[A] | ||
|
||
def info(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoMessageArgsMarker[A] | ||
|
||
def whenInfoEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.infoCode[A] | ||
|
||
// Debug | ||
|
||
def debug(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessage[A] | ||
|
||
def debug(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageCause[A] | ||
|
||
def debug(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageArgs[A] | ||
|
||
def debug(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageMarker[A] | ||
|
||
def debug(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageCauseMarker[A] | ||
|
||
def debug(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugMessageArgsMarker[A] | ||
|
||
def whenDebugEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.debugCode[A] | ||
|
||
// Trace | ||
|
||
def trace(message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessage[A] | ||
|
||
def trace(message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageCause[A] | ||
|
||
def trace(message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageArgs[A] | ||
|
||
def trace(marker: Marker, message: String)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageMarker[A] | ||
|
||
def trace(marker: Marker, message: String, cause: Throwable)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageCauseMarker[A] | ||
|
||
def trace(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceMessageArgsMarker[A] | ||
|
||
def whenTraceEnabled(body: Unit)(implicit a: A): Unit = macro Scala2LoggerTakingImplicitMacro.traceCode[A] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.typesafe.scalalogging | ||
|
||
import org.slf4j.{Marker, Logger as Underlying } | ||
import scala.language.experimental.macros | ||
|
||
trait LoggerImpl { | ||
def underlying: Underlying | ||
|
@@ -54,4 +55,87 @@ trait LoggerImpl { | |
inline def trace(inline marker: Marker, inline message: String, inline cause: Throwable): Unit = ${LoggerMacro.traceMessageCauseMarker('underlying, 'marker, 'message, 'cause)} | ||
inline def trace(inline marker: Marker, inline message: String, inline args: Any*): Unit = ${LoggerMacro.traceMessageArgsMarker('underlying, 'marker, 'message, 'args)} | ||
inline def whenTraceEnabled(inline body: Unit): Unit = ${LoggerMacro.traceCode('underlying, 'body)} | ||
|
||
//scala 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the rest is a copy of the scala 2 macro definitions to be compiled in scala 3. Then these can be used from either scala 3 or 2. |
||
|
||
// Error | ||
|
||
def error(message: String): Unit = macro Scala2LoggerMacro.errorMessage | ||
|
||
def error(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCause | ||
|
||
def error(message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgs | ||
|
||
def error(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.errorMessageMarker | ||
|
||
def error(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.errorMessageCauseMarker | ||
|
||
def error(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.errorMessageArgsMarker | ||
|
||
def whenErrorEnabled(body: Unit): Unit = macro Scala2LoggerMacro.errorCode | ||
|
||
// Warn | ||
|
||
def warn(message: String): Unit = macro Scala2LoggerMacro.warnMessage | ||
|
||
def warn(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCause | ||
|
||
def warn(message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgs | ||
|
||
def warn(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.warnMessageMarker | ||
|
||
def warn(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.warnMessageCauseMarker | ||
|
||
def warn(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.warnMessageArgsMarker | ||
|
||
def whenWarnEnabled(body: Unit): Unit = macro Scala2LoggerMacro.warnCode | ||
|
||
// Info | ||
|
||
def info(message: String): Unit = macro Scala2LoggerMacro.infoMessage | ||
|
||
def info(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCause | ||
|
||
def info(message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgs | ||
|
||
def info(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.infoMessageMarker | ||
|
||
def info(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.infoMessageCauseMarker | ||
|
||
def info(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.infoMessageArgsMarker | ||
|
||
def whenInfoEnabled(body: Unit): Unit = macro Scala2LoggerMacro.infoCode | ||
|
||
// Debug | ||
|
||
def debug(message: String): Unit = macro Scala2LoggerMacro.debugMessage | ||
|
||
def debug(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCause | ||
|
||
def debug(message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgs | ||
|
||
def debug(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.debugMessageMarker | ||
|
||
def debug(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.debugMessageCauseMarker | ||
|
||
def debug(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.debugMessageArgsMarker | ||
|
||
def whenDebugEnabled(body: Unit): Unit = macro Scala2LoggerMacro.debugCode | ||
|
||
// Trace | ||
|
||
def trace(message: String): Unit = macro Scala2LoggerMacro.traceMessage | ||
|
||
def trace(message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCause | ||
|
||
def trace(message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgs | ||
|
||
def trace(marker: Marker, message: String): Unit = macro Scala2LoggerMacro.traceMessageMarker | ||
|
||
def trace(marker: Marker, message: String, cause: Throwable): Unit = macro Scala2LoggerMacro.traceMessageCauseMarker | ||
|
||
def trace(marker: Marker, message: String, args: Any*): Unit = macro Scala2LoggerMacro.traceMessageArgsMarker | ||
|
||
def whenTraceEnabled(body: Unit): Unit = macro Scala2LoggerMacro.traceCode | ||
|
||
} |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is essentially a rename, with minor changes
Scala2LoggerMacro
to avoid a name clash