geirolz / fly4s

A lightweight, simple and functional wrapper of Flyway using cats effect.

Home Page:https://geirolz.github.io/fly4s/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Options regarding loggers?

WeissP opened this issue · comments

I am attempting to change the log level of fly4s (or flyway) to Warning, but I am unable to locate an option for that. I have also experimented with setting the environment variables FLYWAY_LOGGERS to slf4j, but it doesn't help either.

Would it be a good choice to include the option loggers in Fly4sConfig? I am really quite new to Scala, so please forgive me if I have misunderstood anything.

Hi @WeissP sorry for the late reply.
Fly4s doesn't add any logger so you should look for Flyway config.

Here I see a similar issue / request, try to have a look.
flyway/flyway#3651

I'm quite busy at the moment, I try to help you as soon as I can!
Could you please post a snipped of what are doing ? Maybe can helps

Flyway allows to set a logger in the config, which is then used. When this setting is empty or set to "auto", then Flyway attempts to detect available loggers. Ever since they supported slf4j 2.x, the detection of slf4j 1.x is borked, even though they seem to think it should be fixed by now (see the issue you linked). But instead it uses java.util.logging (which is always available) or another logger if available.

There are two ways we can work around this issue: (1) Use jul-to-slf4j or (2) configure Flyway to use slf4j. The latter is currently not possible with fly4s, because Fly4sConfig does not expose this setting and there is no public creation method for Fly4s that allows us to set/modify the Flyway Java config (those are hidden behind Unsafe, which is only visible within the fly4s package).

It would be nice if there was a way to use the Flyway Java config, but there isn't. You can create a Fly4s config from a Flyway config, but it would loose all configs that are not directly supported by Fly4s.

To enable solution (2), the loggers setting would need to be added to Fly4sConfig:

@FluentCopy(collection = true)
case class Fly4sConfig(
  ...
  loggers: List[String] = defaultLoggers
  ...
) extends Fly4sConfigContract

private[fly4s] object Fly4sConfigDefaults {
  ...
  val defaultLoggers: List[String] = List.empty
  ...
}

private[fly4s] trait Fly4sConfigBuilder {
  ...

  def fromJava(c: Configuration): Fly4sConfig =
    new Fly4sConfig(
      ...
      loggers = c.getLoggers.toList
      ...
    )

  def toJava(
    c: Fly4sConfig,
    classLoader: ClassLoader = Thread.currentThread.getContextClassLoader
  ): Try[Configuration] = Try {
    new FluentConfiguration(classLoader)
      ...
      .loggers(c.loggers*)
      ...
  }

  ...
}

What do you think @geirolz?

Until that solution exists or there is a way to modify the Flyway config, we can only use solution (1). To use the jul-to-slf4j bridge, we need to add "org.slf4j" % "jul-to-slf4j" % "1.7.36" as a dependency and add these two lines to our app:

  SLF4JBridgeHandler.removeHandlersForRootLogger()
  SLF4JBridgeHandler.install()

Hi @ex-ratt thank you for reporting all these details!
I'm gonna add loggers as a config parameter and thinking how to safely expose fromJavaConfiguration

Please have a look at #279 and #278
Fixed in v1.0.1

I tried it today and it works like a charm. I like the constants for the loggers and the solution regarding the base configuration in case anyone needs another setting.

I'm happy it helps, thanks you both (@ex-ratt, @WeissP ) again for reporting this issue 👍