Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: include logging3 into tofu aggregted modules #1317

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 51 additions & 34 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -241,41 +241,58 @@ lazy val loggingEnumeratum = projectMatrix
.jvmPlatform(scala2And3Versions)
.dependsOn(loggingStr)

lazy val logging = projectMatrix
.in(modules / "logging")
.aggregate(
loggingStr,
loggingDer,
loggingLayout,
loggingShapeless,
loggingRefined,
loggingLog4Cats,
loggingLog4CatsLegacy,
loggingLogstashLogback,
)
.settings(
defaultSettings,
name := "tofu-logging"
)
.dependsOn(loggingStr, loggingDer, loggingLayout, loggingShapeless, loggingRefined, loggingLog4Cats)
.jvmPlatform(scala2Versions)
lazy val logging = {
def projectRefFromMatrix(pm: ProjectMatrix, scalaVersion: String): ProjectReference = {
val projects = pm.filterProjects(Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion(scalaVersion)))
projects.headOption match {
case Some(p) => p
case None => throw new Exception(s"Can't found $scalaVersion axis for ${pm}")
}
}

lazy val logging3 = projectMatrix
.in(modules / "logging")
.aggregate(
loggingStr,
loggingDer,
loggingLayout,
loggingRefined,
loggingLog4Cats,
loggingLogstashLogback,
)
.settings(
defaultSettings,
name := "tofu-logging"
)
.dependsOn(loggingStr, loggingDer, loggingLayout, loggingRefined, loggingLog4Cats)
.jvmPlatform(List(Version.scala3))
val modulesSettings =
List(
// ($project, $haScala3, $dependsOn)
(loggingStr, true, true),
(loggingDer, true, true),
(loggingLayout, true, true),
(loggingShapeless, false, true),
(loggingRefined, true, true),
(loggingLog4Cats, true, true),
(loggingLogstashLogback, true, true),
)

val initial = ProjectMatrix("logging", modules / "logging")
scala2And3Versions.foldLeft(initial) { case (prMatrix, scalaVersionValue) =>
val scalaAxis = VirtualAxis.scalaABIVersion(scalaVersionValue)
prMatrix.customRow(
autoScalaLibrary = true,
axisValues = Seq(VirtualAxis.jvm, scalaAxis),
process = (pr: Project) => {
val filterScala =
if (scalaVersionValue.startsWith("3")) identity[Boolean](_)
else (_: Boolean) => true
val (aggModules, dependsOnModules) =
modulesSettings.foldLeft((List.empty[ProjectReference], List.empty[ClasspathDependency])) {
case ((agg, dependsOn), (prM, hasScala3, isInDependsOn)) if filterScala(hasScala3) =>
val ref = projectRefFromMatrix(prM, scalaVersionValue)
val nextAgg = ref :: agg
val nextDependsOn = if (isInDependsOn) ClasspathDependency(ref, None) :: dependsOn else dependsOn
(nextAgg, nextDependsOn)
case (acc, _) => acc
}

pr.aggregate(aggModules: _*)
.settings(
defaultSettings,
scalaVersion := scalaVersionValue,
name := "tofu-logging"
)
.dependsOn(dependsOnModules: _*)
}
)
}
}

val util = modules / "util"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.read.ListAppender
import com.fasterxml.jackson.core.{JsonFactory, JsonGenerator}
import derevo.derive
import org.scalatest.funsuite.AnyFunSuite
import org.slf4j.LoggerFactory
import tofu.Delay
Expand Down Expand Up @@ -55,11 +54,15 @@ class TofuLoggingProviderSuite extends AnyFunSuite {
}

object TofuLoggingProviderSuite {
@derive(tofu.logging.derivation.loggable)
final case class LoggingContext(inner: LoggingContextInner, what: String)
object LoggingContext {
implicit val loggable: Loggable[LoggingContext] = tofu.logging.derivation.loggable.instance
}

@derive(tofu.logging.derivation.loggable)
final case class LoggingContextInner(keks: Int, shreks: Int)
object LoggingContextInner {
implicit val loggable: Loggable[LoggingContextInner] = tofu.logging.derivation.loggable.instance
}

val ExampleCtx = LoggingContext(LoggingContextInner(2, 3), "swamp")
}
Loading