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 1 commit
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
1 change: 1 addition & 0 deletions core/src/main/scala-2/fly4s/data/Fly4sConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ case class Fly4sConfig(
defaultSchemaName: Option[String] = defaultDefaultSchemaName,
schemaNames: Option[NonEmptyList[String]] = defaultSchemaNames,
lockRetryCount: Int = defaultLockRetryCount,
loggers: List[LoggerType] = defaultLoggers,
// --- migrations ---
installedBy: Option[String] = defaultInstalledBy,
locations: List[Location] = defaultLocations,
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala-3/fly4s/data/Fly4sConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ case class Fly4sConfig(
defaultSchemaName: Option[String] = defaultDefaultSchemaName,
schemaNames: Option[NonEmptyList[String]] = defaultSchemaNames,
lockRetryCount: Int = defaultLockRetryCount,
loggers: List[LoggerType] = defaultLoggers,
// --- migrations ---
installedBy: Option[String] = defaultInstalledBy,
locations: List[Location] = defaultLocations,
Expand Down Expand Up @@ -68,6 +69,9 @@ object Fly4sConfig extends Fly4sConfigBuilder:
def withLockRetryCount(lockRetryCount: Int): Fly4sConfig =
i.copy(lockRetryCount = lockRetryCount)

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

def withInstalledBy(installedBy: Option[String]): Fly4sConfig =
i.copy(installedBy = installedBy)

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/fly4s/data/Fly4sConfigBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 +120,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 +171,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
30 changes: 30 additions & 0 deletions core/src/main/scala/fly4s/data/LoggerType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.

sealed trait LoggerType
object LoggerType {
case object Auto extends LoggerType
case object Console extends LoggerType
case object Slf4j extends LoggerType
case object Log4j2 extends LoggerType
case object ApacheCommons extends LoggerType
case class Custom(fullyQualifiedClassName: String) extends LoggerType

def fromFlywayValue(value: String): LoggerType = value match {
case "auto" => Auto
case "console" => Console
case "slf4j" => Slf4j
case "log4j2" => Log4j2
case "apache-commons" => ApacheCommons
case custom => Custom(custom)

Check notice

Code scanning / Codacy-scalameta-pro (reported by Codacy)

Prohibit case statement pattern match from being lowercase. Note

Lower case pattern matching.

Check notice

Code scanning / Scalastyle (reported by Codacy)

Lowercase pattern match (surround with ``, or add : Any). Note

Lowercase pattern match (surround with ``, or add : Any).
}

def toFlywayValue(ltype: LoggerType): String =
ltype match {
case LoggerType.Auto => "auto"
case LoggerType.Console => "console"
case LoggerType.Slf4j => "slf4j"
case LoggerType.Log4j2 => "log4j2"
case LoggerType.ApacheCommons => "apache-commons"
case LoggerType.Custom(fullyQualifiedClassName) => fullyQualifiedClassName
}
}
Loading