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

Add loggers configuration #278

Merged
merged 4 commits into from
Feb 12, 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
6 changes: 6 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sbt.project
import ModuleMdocPlugin.autoImport.mdocScalacOptions
import com.typesafe.tools.mima.core.{DirectMissingMethodProblem, ProblemFilters}

lazy val prjName = "fly4s"
lazy val prjPackageName = prjName.replaceAll("[^\\p{Alpha}\\d]+", ".")
Expand Down Expand Up @@ -42,6 +43,11 @@ lazy val core: Project =
publishAs = Some(prjName),
mimaCompatibleWith = Set("1.0.0")
).settings(
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("fly4s.data.Fly4sConfig.apply"),
ProblemFilters.exclude[DirectMissingMethodProblem]("fly4s.data.Fly4sConfig.copy"),
ProblemFilters.exclude[DirectMissingMethodProblem]("fly4s.data.Fly4sConfig.this")
),
libraryDependencies ++= {
CrossVersion.partialVersion(Keys.scalaVersion.value) match {
case Some((2, _)) => ProjectDependencies.for2_13_Only
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala-2/fly4s/data/Fly4sConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ case class Fly4sConfig(
baselineOnMigrate: Boolean = defaultBaselineOnMigrate,
outOfOrder: Boolean = defaultOutOfOrder,
skipDefaultCallbacks: Boolean = defaultSkipDefaultCallbacks,
skipDefaultResolvers: Boolean = defaultSkipDefaultResolvers
skipDefaultResolvers: Boolean = defaultSkipDefaultResolvers,
// --- mima after 1.0.0 ---
loggers: List[LoggerType] = defaultLoggers
) extends Fly4sConfigContract
object Fly4sConfig extends Fly4sConfigBuilder
7 changes: 6 additions & 1 deletion core/src/main/scala-3/fly4s/data/Fly4sConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
baselineOnMigrate: Boolean = defaultBaselineOnMigrate,
outOfOrder: Boolean = defaultOutOfOrder,
skipDefaultCallbacks: Boolean = defaultSkipDefaultCallbacks,
skipDefaultResolvers: Boolean = defaultSkipDefaultResolvers
skipDefaultResolvers: Boolean = defaultSkipDefaultResolvers,
// --- mima after 1.0.0 ---
loggers: List[LoggerType] = defaultLoggers
) extends Fly4sConfigContract
object Fly4sConfig extends Fly4sConfigBuilder:

Expand All @@ -68,6 +70,9 @@
def withLockRetryCount(lockRetryCount: Int): Fly4sConfig =
i.copy(lockRetryCount = lockRetryCount)

def withLoggers(loggers: List[LoggerType]): Fly4sConfig =
i.copy(loggers = loggers)

Check warning on line 75 in core/src/main/scala-3/fly4s/data/Fly4sConfig.scala

View check run for this annotation

Codecov / codecov/patch

core/src/main/scala-3/fly4s/data/Fly4sConfig.scala#L75

Added line #L75 was not covered by tests
def withInstalledBy(installedBy: Option[String]): Fly4sConfig =
i.copy(installedBy = installedBy)

Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/fly4s/data/Fly4sConfigBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
val defaultSchemaName: Option[String]
val schemaNames: Option[NonEmptyList[String]]
val lockRetryCount: Int
val loggers: List[LoggerType]

// --- migrations ---
val installedBy: Option[String]
Expand Down Expand Up @@ -63,6 +64,7 @@
val defaultDefaultSchemaName: Option[String] = None
val defaultSchemaNames: Option[NonEmptyList[String]] = None
val defaultLockRetryCount: Int = 50
val defaultLoggers: List[LoggerType] = List(LoggerType.Auto)

Check notice

Code scanning / Scalastyle (reported by Codacy)

Field name does not match the regular expression '^[A-Z][A-Za-z0-9]*$'. Note

Field name does not match the regular expression '^[A-Z][A-Za-z0-9]*$'.

// --- migrations ---
val defaultInstalledBy: Option[String] = None
Expand Down Expand Up @@ -119,6 +121,7 @@
defaultSchemaName = Option(c.getDefaultSchema),
schemaNames = NonEmptyList.fromList(c.getSchemas.toList),
lockRetryCount = c.getLockRetryCount,
loggers = c.getLoggers.toList.map(LoggerType.fromFlywayValue(_)),
// ---------- migrations ----------
locations = c.getLocations.toList,
installedBy = Option(c.getInstalledBy),
Expand Down Expand Up @@ -169,7 +172,7 @@
.defaultSchema(c.defaultSchemaName.orNull)
.schemas(c.schemaNames.map(_.toList).getOrElse(Nil)*)
.lockRetryCount(c.lockRetryCount)

.loggers(c.loggers.map(LoggerType.toFlywayValue(_))*)
// ---------- migrations ----------
.locations(c.locations*)
.installedBy(c.installedBy.orNull)
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/scala/fly4s/data/LoggerType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fly4s.data

Check notice

Code scanning / Scalastyle (reported by Codacy)

File must not end with newline character. Note

File must not end with newline character.

Check notice

Code scanning / Scalastyle (reported by Codacy)

Header does not match expected text. Note

Header does not match expected text.

abstract sealed class LoggerType(val tpeValue: String)
object LoggerType {
case object Auto extends LoggerType("auto")
case object Console extends LoggerType("console")
case object Slf4j extends LoggerType("slf4j")
case object Log4j2 extends LoggerType("log4j2")
case object ApacheCommons extends LoggerType("apache-commons")
case class Custom(fullyQualifiedClassName: String) extends LoggerType(fullyQualifiedClassName)

def toFlywayValue(ltype: LoggerType): String = ltype.tpeValue

def fromFlywayValue(value: String): LoggerType = value match {
case Auto.tpeValue => Auto
case Console.tpeValue => Console
case Slf4j.tpeValue => Slf4j
case Log4j2.tpeValue => Log4j2
case ApacheCommons.tpeValue => ApacheCommons
case custom => Custom(custom)

Check warning on line 20 in core/src/main/scala/fly4s/data/LoggerType.scala

View check run for this annotation

Codecov / codecov/patch

core/src/main/scala/fly4s/data/LoggerType.scala#L16-L20

Added lines #L16 - L20 were not covered by tests
}
}
Loading